如何检测声音文件何时完成?
我正在广播接收器活动中使用此代码播放声音文件:
notification.sound = Uri.parse("android.resource://emad.app/raw/seven_chimes");
我想检测此文件何时完成播放。
我尝试了这样的循环,但我认为这只对媒体播放器有好处,因为它总是 = false,即使我确保声音文件仍在播放:
/*
* Stay here until the chime sound is finished.
*/
while (manager.isMusicActive()){
}
你能告诉我我应该使用什么来代替 manager.isMusicActive ()?
I am playing a sound file using this code inside a broadcast receiver activity:
notification.sound = Uri.parse("android.resource://emad.app/raw/seven_chimes");
I would like to detect when this file has finished playing.
I tried a loop like this but I think this is only good for the media player because it always = false even though I made sure the sound file was still playing:
/*
* Stay here until the chime sound is finished.
*/
while (manager.isMusicActive()){
}
Can you show me what I should use instead of manager.isMusicActive()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 MediaPlayer 类并添加一个 Completion 侦听器,以便在声音播放完毕时激活
You can use the MediaPlayer class and add a Completion listener to be activated when the sound finishes playing
不使用广播接收器,但这对我当前的项目有用,使用 Kotlin 跟踪音频文件何时完成播放。
isPlaying 是布尔值,如果有人感到困惑,我会解释更多。希望它将来对其他人有帮助。快乐编码!
Not working with broadcast receiver but this is what worked for my current project using Kotlin to track when the audio file has finished playing.
isPlaying is boolean, I will explain more if someone is confused. Hope it helps someone else in the future. Happy coding!
尝试使用服务来播放音乐..
播放一次后,停止您的服务,您可以在 onDestroy() 服务方法上添加您的程序。
希望有帮助:)
try using service to play the music..
after it play once, then stop your service and you can add your program on the onDestroy() service method..
hope it helps :)