1

シークバーの非表示を停止する方法が見つかりません。曲が再生されるとすぐに、シークバーは 2 ~ 3 秒後に非表示になります。私はこれに本当に慣れていないので、この問題にどのようにアプローチできるかよくわかりません。曲の再生中に mediaController.show() をメソッドに入れてみましたが、うまくいきませんでした。以下のYoutubeチャンネルからこのコードを見つけました。コードは次のとおりです。

 public class MainActivity extends ListActivity implements OnPreparedListener,
  MediaController.MediaPlayerControl {

private static final String TAG = "AudioPlayer";
private ListView list;
private MainArrayAdapter adapter;
private MediaPlayer mediaPlayer;
private MediaController mediaController;
private String audioFile;
private Handler handler = new Handler();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    list = getListView();

    mediaPlayer = new MediaPlayer();
    mediaPlayer.setOnPreparedListener(this);
    mediaController = new MediaController(this);

    ArrayList<String> array_list_music = new ArrayList<String>();
    array_list_music.add("Sammy Kaye And His Orchestra" + " ### "
            + "Minka  (1941)" + " ### "
            + "http://incoming.jazz-on-line.com/a/mp3w/1941_149.mp3");
    adapter = new MainArrayAdapter(MainActivity.this, array_list_music);
    setListAdapter(adapter);

    list.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            Object item = getListView().getItemAtPosition(arg2);
            String the_list_item = item.toString();

            Toast.makeText(MainActivity.this,
                    "You clicked " + the_list_item, Toast.LENGTH_LONG)
                    .show();

            String[] aux = the_list_item.split(" ### ");
            String url_to_play = aux[2];

            playAudio(url_to_play);

        }
    });

}

private void playAudio(String url_to_play) {

    //----- stop & reset 
    try {
        mediaPlayer.stop();
        mediaPlayer.reset();
    } catch (Exception e) {
        // TODO: handle exception
    }

    try {
        mediaPlayer.setDataSource(url_to_play);
        mediaPlayer.prepare();
        mediaPlayer.start();
    } catch (Exception e) {
        Log.e(TAG, "Could not open file " + url_to_play + " for playback.",
                e);
    }

}
@Override
public boolean onTouchEvent(MotionEvent event) {
    mediaController.show();
    return true;
}

@Override
protected void onStop() {
    super.onStop();
    mediaController.hide();
    mediaPlayer.stop();
    mediaPlayer.release();
}

@Override
public boolean canPause() {
    return true;
}

@Override
public boolean canSeekBackward() {

    return true;
}

@Override
public boolean canSeekForward() {
    return true;
}

@Override
public int getBufferPercentage() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public int getCurrentPosition() {
    return mediaPlayer.getCurrentPosition();
}

@Override
public int getDuration() {
    return mediaPlayer.getDuration();
}

@Override
public boolean isPlaying() {
    return mediaPlayer.isPlaying();
}

@Override
public void pause() {
    mediaPlayer.pause();
}

@Override
public void seekTo(int arg0) {
    mediaPlayer.seekTo(arg0);
}

@Override
public void start() {
    mediaPlayer.start();

}
public void onPrepared(MediaPlayer mediaPlayer) {
    Log.d(TAG, "onPrepared");
    mediaController.setMediaPlayer(this);
    mediaController.setAnchorView(list);
    mediaController.show();

    handler.post(new Runnable() {
        public void run() {
            mediaController.setEnabled(true);
            mediaController.show();

        }
    });
   }
  }
4

0 に答える 0