如何通过点击按钮通知播放下一首歌曲媒体播放器

时间:2017-05-23 13:35:16

标签: android service notifications media-player

我想在媒体播放器中播放下一首歌曲,点击按钮通知服务播放我的歌曲我使用此代码:

public void playSongWithIndex(final int songIndex) {

      try {
        G.mediaPlayer.reset();
        G.mediaPlayer.setDataSource(songList.get(songIndex).getFile_128());
        G.mediaPlayer.prepareAsync();
        G.mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
          @Override
          public void onPrepared(MediaPlayer mediaPlayer) {
            startService = new Intent(G.context, MediaPlayerService.class);
            startService.setAction(MediaPlayerService.ACTION_PLAY);
            G.context.startService(startService);
            G.mediaPlayer.start();   
            seekBar.setMax(G.mediaPlayer.getDuration());
            timer = new Timer();
            timer.schedule(new MainTimer(), 0, 1000);

          }
        });
      }

和我的服务代码:

@Override
    public void onSkipToNext() {
    super.onSkipToNext();
buildNotification(generateAction(android.R.drawable.ic_media_pause, "Pause", ACTION_PAUSE));

    }

请帮忙怎么做?

1 个答案:

答案 0 :(得分:0)

阅读这篇文章

https://developer.android.com/reference/android/support/v7/app/NotificationCompat.MediaStyle.html

此通知方式专门针对媒体:

" ...您可以在标准视图中宣传最多3个与常规内容一起显示的操作。"