Android的默认媒体播放器和QUOT;启动"后"停止"错误(com.android.music.musicservicecommand)媒体播放器、错误、QUOT、A

由网友(、半场梦一场空)分享简介:当我发送到默认播放器Intent i = new Intent("com.android.music.musicservicecommand");i.putExtra("command", "play");ACTIVITY.sendBroadcast(i);开始播放。当我送it starts to play....

当我发送到默认播放器

Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", "play");
ACTIVITY.sendBroadcast(i);

开始播放。当我送

it starts to play. When i send

Intent i = new Intent("com.android.music.musicservicecommand");
        i.putExtra("command", "stop");
        ACTIVITY.sendBroadcast(i);

停止。但是当我尝试再次播放,然后它不玩。它只是起着一秒钟,然后再停止。我在日志中看到我得到两个意图。在

it stops. but when I try to play again then it doesnt play. It just plays for a second and then stops again. I saw on the log i get two intents. The

intent.getBooleanExtra("playing", false);

第一次是真,然后是假。当我尝试了togglePause时这是没有发生。我还注意到,当我将同时播放的音乐的Andr​​oid应用程序和谷歌播放音乐开始。谁能帮助??

the first time is "true" and then is "false". This isn't happening when i try the "togglepause". I also noticed that when i send play both the android music app and the google play music starts. Anyone help??

-------------------编辑-----------------其实我想通了,谷歌播放音乐是造成这一点。显然,这两个应用得到的意图,当我送戏,与IsPlaying模块= true,并且谷歌音乐播放器的答案播放音乐IsPlaying模块= FALSE。你知道什么办法解决呢?发送或只接收弗朗的默认播放器??

------------------- EDIT ----------------- Actually I figured out that google play music was causing that. Apparently both apps get the intent and when i send play , the music player answers with isPlaying = true and the google play music isPlaying = false. Do you know any way to fix that? to send or to receive only fron the default player??

推荐答案

一个有点晚,但发布为别人谁正在寻找这一点。您可以通过发送一个有序的广播到媒体按钮已被pressed及以下released.The code将发挥或者根据当前状态,暂停音乐系统控制默认媒体播放器:

A little late but posting for others who are searching for this. You can control default media player by sending an ordered broadcast to the system that a media button has been pressed and released.The following code will play or pause music depending on the current state:

  long eventtime = SystemClock.uptimeMillis(); 
  Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); 
  KeyEvent downEvent = new KeyEvent(eventtime, eventtime, 
  KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0); 
  downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent); 
  sendOrderedBroadcast(downIntent, null); 

  Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null); 
  KeyEvent upEvent = new KeyEvent(eventtime, eventtime, 
  KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, 0); 
  upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent); 
  sendOrderedBroadcast(upIntent, null); 

您可以提醒,未来或previous轨道按钮已被pressed系统以同样的方式。

The same way you can alert the system that the next or previous track button has been pressed.

阅读全文

相关推荐

最新文章