如何检测,当声音文件完成? [英] How do you detect when a sound file has finished?

查看:171
本文介绍了如何检测,当声音文件完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是广播接收器的工作这里面​​code播放声音文件:

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.

我想这样的一个循环,但我认为这是唯一的好媒体播放器,因为它总是尽管我确信声音文件还在玩= FALSE:

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()){
   }

你能告诉我,我应该用manager.isMusicActive什么,而不是()

Can you show me what I should use instead of manager.isMusicActive()

感谢。

确实, 伊马德

推荐答案

您可以使用的MediaPlayer类,并添加完成监听器被激活时,声音播放完

You can use the MediaPlayer class and add a Completion listener to be activated when the sound finishes playing

MediaPlayer mp = MediaPlayer.create(this,Uri.parse("android.resource://emad.app/raw/seven_chimes"));

mp.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                performOnEnd();
            }

            });

    mp.start();

这篇关于如何检测,当声音文件完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆