android - 多次按下后停止播放声音

标签 android eclipse audio media-player

我创建了一个声音短的应用程序。当我按下按钮播放它们之后,没有问题

但是在多次中按20或更多;应用程序不会崩溃但会停止播放声音

我想学习;我该如何做一个无限工作声音按钮?谢谢

我在onDestroy()上写了它,但是不起作用。我也这样写;但这也不起作用

protected void onCreate(Bundle savedInstanceState) {

    final MediaPlayer mediaPlayer;

    mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.x1);

    ImageButton1 = (ImageButton) findViewById(R.id.imageButton1);
    ImageButton1.setOnClickListener(new View.OnClickListener()

    {

        @Override
        public void onClick(View v) {

                mediaPlayer.start();
                mediaPlayer.release();

...

最佳答案

完成对release()对象的处理后,您可能不会在它们上调用MediaPlayer。从documentation:

When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances will result in an exception.

关于android - 多次按下后停止播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24249929/

相关文章:

python - 向 Eclipse 控制台中运行的程序发送 SIGINT (Ctrl-C)

java - 录制声音,然后在Android上使用/保存声音

android - 由于频繁断网,repo 同步卡在 99%

android - 如何从 dart/flutter 将 int/integer 值作为 json 发布

java - 无法更改 Android Activity

java - 在 eclipse 中添加 org.glassfish.jersey.archetypes

java - Frege 在引用的项目或外部 jar 中找不到类

java - 在java中从Google Drive下载pdf和tif文件

android - AudioRecord同时播放音频-访问输出播放数据

iphone - 我可以从 MPMusicPlayerController 获取 Audio Session /应用音频单元进行播放吗?