Android的媒体播放器:如何监听媒体播放器的事件? [英] Android media player : How can I listen for media player events?

查看:372
本文介绍了Android的媒体播放器:如何监听媒体播放器的事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿家伙,所以我下面的 http://developer.android.com /guide/topics/media/mediaplayer.html 解释的MediaPlayer的,我想知道我怎么能倾听来自玩家的活动,如播放,暂停,停止等...

Hey guys so I am following the http://developer.android.com/guide/topics/media/mediaplayer.html explanation of the MediaPlayer and I am wondering how can I listen to the events from the player such as playing, paused, stopped etc...

本页面显示如何只为在preparedListener ,所以我在想,如果有对玩家的其他国家,或如何事件监听我会处理玩家的不同状态?

The page shows how to listen only for the onPreparedListener and so I was wondering if there are events for the the other states of the player, or how would I handle the different states of the player?

谢谢!

推荐答案

不幸的是,你无法检测是否媒体播放器暂停或停止, MediaPlayer的类有一个功能 IsPlaying模块(),将检测到,如果它在播放状态下或没有。你可以做一些努力,检测如下暂停条件:

Unfortunately you can not detect if the mediaplayer is paused or stopped, The MediaPlayer class has one function isPlaying() which will detect if it's in playing mode or not. You can do some effort for detecting pause condition as below :

mediaplayer.pause();
//get the length of the mediaplayer here
length=mediaplayer.getCurrentPosition();
//and for resume you can do the following
mediaplayer.seekTo(length);
mediaplayer.start();

有关检查媒体播放器的停止状态,您可以检查如上,唯一的变化是,将达到最大的时刻。就这样。或者,您可以使用 setOnCompletionListener()

For checking stopping state of mediaplayer, you can check as above , the only change will be the time which will reach to maximum. That's all. Or, You can use setOnCompletionListener()

还要检查这个答案,怎么媒体播放器到达不同的状态。 <一href="http://stackoverflow.com/questions/3855151/how-to-resume-the-mediaplayer/3855609#3855609">Click这里

Also check this answer , how mediaplayer reaches different states. Click here

该媒体播放器包括以下监听器:

The mediaplayer contains following listener :

 1. setOnBufferingUpdateListener
 2. setOnErrorListener
 3. setOnInfoListener
 4. setOnCompletionListener
 5. setOnSeekCompleteListener
 6. setOnTimedTextListener
 7. setOnVideoSizeChangedListener
 8. setOnPreparedListener

希望这会帮助你。 :)

Hope this will help you . :)

这篇关于Android的媒体播放器:如何监听媒体播放器的事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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