例如的MediaPlayer:停止行为就像一个暂停就像、行为、MediaPlayer

2023-09-06 04:59:03 作者:思如影

我写了一个小的音乐播放控制测试应用程序。我有播放,暂停,停止,快退按钮。我的问题是,该     player.stop();行为是完全相同的方式     player.pause();我打电话球员。prepare()player.stop(右后),这样我可以有准备的start()操作的播放器实例。

I wrote a small music playback control test application. I have a play, pause, stop and rewind button. My issue is that that player.stop(); is behaving the same exact way as player.pause(); I am calling player.prepare() right after player.stop() so that i can have the player instance ready for start() operation.

我看不出有任何错误[的IOExceptions或IllegalStateExceptions],而调用prepare()后,我做一个stop()被提出。另外,我不是要求停止后的任何seekTo(0)()。所以,我不会设定位置回到歌曲的开头。

I do not see any errors [IOexceptions or IllegalStateExceptions] being raised while calling the prepare() after i do a stop(). Also, i am not calling any seekTo(0) after stop(). So, i am not setting the position back to the beginning of the song.

我使用的是谷歌的Nexus One手机运行2.3.4。

I am using a Nexus Google One phone running 2.3.4.

任何想法,如果我在做一些愚蠢的事,或者我所观察实际状态机是如何构建的。

Any idea if i am doing something stupid or if what i am observing is actually how the state machine was built.

TIA。

推荐答案

没有状态图的 http://developer.android.com/reference/android/media/MediaPlayer.html 指出停止的意思是停留在停止状态?

doesn't the state diagram http://developer.android.com/reference/android/media/MediaPlayer.html states that stop means "stay in stopped state" ?

调用stop()停止播放和导致的MediaPlayer在开始,暂停,prepared或PlaybackCompleted状态进入停止状态。

Calling stop() stops playback and causes a MediaPlayer in the Started, Paused, Prepared or PlaybackCompleted state to enter the Stopped state.

在停止状态,播放不能启动,直到prepare()或prepareAsync()被称为重新设置MediaPlayer对象到prepared状态。  呼叫停止()具有一个MediaPlayer对象已在停止状态没有影响

Once in the Stopped state, playback cannot be started until prepare() or prepareAsync() are called to set the MediaPlayer object to the Prepared state again. Calling stop() has no effect on a MediaPlayer object that is already in the Stopped state.

有没有肯定的停止()应修改 CurrentPosition

有没有申明调用 prepare()应修改 CurrentPosition

There's no affirmation that calling the prepare() should change the CurrentPosition.

所以,要到音乐的开始,你应该mannualy设置其位置。

So, to go to the beginning of the music, you should mannualy set its position.

不过,我同意你的看法。因为暂停()法规定,将继续从当前位置打球,我希望它回到一开始的时候停止()被调用。

But I agree with you. Since the pause() method states it will resume playing from the current position, I'd expect it get back to the beginning when stop() is called.

和它有一定的影响,当你需要调用 prepare()

And it has some impact when you need to call the prepare()

例如,调用prepare()可能需要很长的时间来执行,因为它可能涉及获取和解码媒体数据。

For example, the call to prepare() can take a long time to execute, because it might involve fetching and decoding media data.

所以停止()需要调用 prepare(),可以使需要更长的时间,而暂停()具有影响较少:你可以调用开始()右后

so stop() needs to call prepare() that can make it take longer, while pause() has less impact: you can call the start() right after.