xiaoniqiu2008 2016-07-30 11:51 采纳率: 0%
浏览 1755
已结题

android中mMediaPlayer播放前停止其它声音

我想学做一个英语点读软件,在页面中用不同的按钮点击,会发出不同的声音,这个功能实现了,但我的代码出现问题,点击按钮时候,前一个声音还没播放完也会一起发出声音,我想实现当点击其中一个按钮后,其它按钮的声音先停止,请前辈告诉我如何改进,谢谢。这是我的代码其中一部分:
public void onClick(View v) {

 if(v==imageButton1){
    textView.setText("第一单元 他怎么样?");

    mMediaPlayer=MediaPlayer.create(this, R.raw.lessonname);
    if(!mMediaPlayer.isPlaying()){
         mMediaPlayer.start();
    }
 }
    else if(v==imageButton2){
    textView.setText("这是艾米,她很安静,她很勤奋。");
    mMediaPlayer=MediaPlayer.create(this, R.raw.sentense1);
    if(!mMediaPlayer.isPlaying()){

        mMediaPlayer.start();

    }
    }

    else if(v==imageButton3){
        textView.setText("那是吴一凡,他很聪明,他也很有礼貌。");
        mMediaPlayer=MediaPlayer.create(this, R.raw.sentense2);
        if(!mMediaPlayer.isPlaying()){

            mMediaPlayer.start();

        }
        }

    else if(v==imageButton4){
        textView.setText("你好,我的名字是奥利弗。");
        mMediaPlayer=MediaPlayer.create(this, R.raw.sentense3);
        if(!mMediaPlayer.isPlaying()){

            mMediaPlayer.start();

        }
        }
  • 写回答

3条回答 默认 最新

  • 普通网友 2016-07-30 15:14
    关注

    可以先销毁再调用,或者判断一下

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题