gpt4 book ai didi

android暂停或停止其他音乐播放器的播放实现代码

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 60 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章android暂停或停止其他音乐播放器的播放实现代码由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

代码如下:

复制代码 代码如下:

     public static final String PLAYSTATE_CHANGED = "com.android.music.playstatechanged";     public static final String META_CHANGED = "com.android.music.metachanged";     public static final String QUEUE_CHANGED = "com.android.music.queuechanged";     public static final String PLAYBACK_COMPLETE = "com.android.music.playbackcomplete";     public static final String ASYNC_OPEN_COMPLETE = "com.android.music.asyncopencomplete";     public static final String SERVICECMD = "com.android.music.musicservicecommand";     public static final String CMDNAME = "command";     public static final String CMDTOGGLEPAUSE = "togglepause";     public static final String CMDSTOP = "stop";     public static final String CMDPAUSE = "pause";     public static final String CMDPREVIOUS = "previous";     public static final String CMDNEXT = "next",

  。

   private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {         @Override         public void onReceive(Context context, Intent intent) {             String action = intent.getAction();             String cmd = intent.getStringExtra("command");             if (CMDNEXT.equals(cmd) || NEXT_ACTION.equals(action)) {                 next(true);             } else if (CMDPREVIOUS.equals(cmd) || PREVIOUS_ACTION.equals(action)) {                 prev();             } else if (CMDTOGGLEPAUSE.equals(cmd) || TOGGLEPAUSE_ACTION.equals(action)) {                 if (isPlaying()) {                     pause();                 } else {                     play();                 }             } else if (CMDPAUSE.equals(cmd) || PAUSE_ACTION.equals(action)) {                 pause();             } else if (CMDSTOP.equals(cmd)) {                 pause();                 seek(0);             } else if (MediaAppWidgetProvider.CMDAPPWIDGETUPDATE.equals(cmd)) {                 // Someone asked us to refresh a set of specific widgets, probably                 // because they were just added.                 int[] appWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);                 mAppWidgetProvider.performUpdate(MediaPlaybackService.this, appWidgetIds);             }         }     },

通过分析可以得出要暂停音乐可以有两种方法,一种是直接发送cmd,另外一种是发送action.

  。

如下暂停音乐播放代码:

复制代码 代码如下:

 private void pauseMusic() {
  Intent freshIntent = new Intent();
  freshIntent.setAction("com.android.music.musicservicecommand.pause");
  freshIntent.putExtra("command", "pause");
  sendBroadcast(freshIntent);
 }

最后此篇关于android暂停或停止其他音乐播放器的播放实现代码的文章就讲到这里了,如果你想了解更多关于android暂停或停止其他音乐播放器的播放实现代码的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

60 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com