gpt4 book ai didi

java - 为什么应用程序中的音频停止播放?

转载 作者:行者123 更新时间:2023-12-01 10:01:55 25 4
gpt4 key购买 nike

我有一个程序,每次用户执行某个操作时都会播放声音。但一段时间后,所有音频都不起作用。

示例代码:

public void bPressed(View view) {
MediaPlayer mp = MediaPlayer.create(activity.this, R.raw.audio);
mp.start();
}

最佳答案

您需要使用mp.release();当您完成MediaPlayer时:

As an example, consider the problems that could happen if you forgot to release the MediaPlayer when your activity is stopped, but create a new one when the activity starts again. As you may know, when the user changes the screen orientation (or changes the device configuration in another way), the system handles that by restarting the activity (by default), so you might quickly consume all of the system resources as the user rotates the device back and forth between portrait and landscape, because at each orientation change, you create a new MediaPlayer that you never release. (For more information about runtime restarts, see Handling Runtime Changes.)

http://developer.android.com/intl/es/guide/topics/media/mediaplayer.html

添加 mp.release(); 例如在 onStop()

关于java - 为什么应用程序中的音频停止播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36742621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com