0

具有以下代码来运行 mp3 播客

public void playPodcast( final Uri data){
            new Thread (new Runnable(){
                public void run() {
                  if(!mediaPlayer.isPlaying()){
                        try {
                            mediaPlayer.setDataSource(getApplicationContext(), data);
                        } catch (IllegalArgumentException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (SecurityException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IllegalStateException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        try {
                            mediaPlayer.prepare();
                        } catch (IllegalStateException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        } 
                        mediaFileLengthInMilliseconds = mediaPlayer.getDuration();
                        duracaoPodcast = mediaPlayer.getDuration();

                        mediaPlayer.start();


                        if(!(controlTimer >= 1)){
                            timer();
                            controlTimer++;
                        }

                        primarySeekBarProgressUpdater();


                }
              } 
            }).start();
        }

并关闭用户意图有:

  voltar.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    finish();
                    mediaPlayer.stop();
                }
            });

当用户关闭所有带有android的返回按钮手机的意图时会出现问题,因为它没有:

finish();
mediaPlayer.stop();

只做:

finish();

所以音频仍在播放,即使我回到那个意图暂停:

stop.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                if(mediaPlayer.isPlaying()){
                    mediaPlayer.stop(); 
                    frame.setVisibility(View.INVISIBLE);

                }

            }
        });

按钮不起作用,如果我按下播放,他会在空播放的顶部开始一个新的音频,

知道如何解决吗?

4

1 回答 1

0

据我了解您的问题,请mediaPlayer.stop();输入活动方法。onStop()

于 2012-05-22T15:00:38.150 回答