Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does WeChat Mini Programs get the music playback status?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "How to Get Music Playing Status for Weixin Mini Programs (Mini)." The small editor shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "How to Get Music Playing Status for Weixin Mini Programs" can help you solve the problem.

wx.getBackgroundAudioPlayerState(OBJECT)

Acquire music playback status.

OBJECT Parameter Description:

Parameter type Required Description successFunction No Interface call successful callback function failFunction No Interface call failed callback function completeFunction No Interface call ended callback function (successful or failed call will be executed)

success Return parameter description:

parameter description duration Length of selected audio (unit: s), currentPosition is returned only when music is currently playing, status is returned only when music is currently playing (2: no music is playing, 1: playing, 0: pausing) downloadPercent audio download progress (integer, 80 represents 80%), dataUrl song data link is returned only when music is currently playing, only when music is currently playing

Example code:

wx.getBackgroundAudioPlayerState({ success:function(res){var status = res.statusvar dataUrl = res.dataUrlvar currentPosition = res.currentPositionvar duration = res.durationvar downloadPercent = res.downloadPercent }})wx.playBackgroundAudio(OBJECT)

Use background player to play music. For WeChat client, only one background music can be played at the same time. When the user leaves Mini programs, music will pause; when the user clicks "Show at the top of chat," music will not pause; when the user occupies music player in other Mini programs, music in original Mini programs will stop playing.

OBJECT Parameter Description

Parameter Type Required Description dataUrlString Yes Music Link titleString No Music Title coverImgUrlString No Cover URLsuccessFunction No Interface Call Successful Callback Function FailFunction No Interface Call Failed Callback Function CompleteFunction No Interface Call End Callback Function (successful or failed call will be executed)

sample code

wx.playBackgroundAudio({ dataUrl: '', title: '', coverImgUrl: ''})wx.pauseBackgroundAudio()

Pause music.

sample code

wx.pauseBackgroundAudio()wx.seekBackgroundAudio(OBJECT)

Control music playback progress.

OBJECT Parameter Description

Parameter type Required Description positionNumber is the music position, unit: second successFunction No interface call successful callback function failFunction No interface call failed callback function completeFunction No interface call ended callback function (call successful or failed will be executed)

sample code

wx.seekBackgroundAudio({ position: 30})wx.stopBackgroundAudio()

Stop playing music.

sample code

wx.stopBackgroundAudio()wx.onBackgroundAudioPlay(CALLBACK)

Listen to music playing.

wx.onBackgroundAudioPause(CALLBACK)

Listen to music pause.

wx.onBackgroundAudioStop(CALLBACK)

Listen to music stop.

bug & tip

bug: iOS 6.3.30wx.seekBackgroundAudio will have a short delay

Here is the introduction of "How to Get Music Playing Status for Weixin Mini Programs." Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report