在Android中,控制(播放/暂停)从外部code媒体播放器 [英] In Android, control (play/pause) media player from external code

查看:301
本文介绍了在Android中,控制(播放/暂停)从外部code媒体播放器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新到Android编程。作为第一个业余爱好项目,我想编写一个程序来控制媒体播放器应用程序,特别是播放/暂停(或切换),甚至更好,快进/快退。是否有可能这样做吗?如果是的话,是否有任何教程或样品code?

I'm very new to Android programming. As a first hobby project, I'd like to write a program to control the media player app, in particular play/pause (or toggle) or even better, fast forward/backward. Is it possible to do this? If yes, are there any tutorials or sample code?

非常感谢。

澄清:也许我是不是在我原来的问题不够清楚。我不想播放音频/视频里面我的应用程序,但我想控制其他媒体播放器应用程序(表示默认的音乐应用程序),从我的应用程序。例如,我的应用程序只有一个按钮,如果默认媒体播放器的应用程序正在播放一些音乐(背景),我按下该按钮,音乐暂停。

Clarification: maybe I was not clear enough in my original question. I don't want to play audio/video inside my app, but I want to control other media player apps (says the default music app) from my app. For example, my app has only one button, if the default media player app is playing some music (in the background) and I push that button, the music is paused.

推荐答案

下面code暂停默认通过sendBroadcast媒体播放器:

The Following code is paused default Media Player via sendBroadcast:

   AudioManager mAudioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);    

    if (mAudioManager.isMusicActive()) {

    Intent i = new Intent("com.android.music.musicservicecommand");

    i.putExtra("command", "pause");
    YourApplicationClass.this.sendBroadcast(i);
    }   

这篇关于在Android中,控制(播放/暂停)从外部code媒体播放器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆