媒体播放器应停止以编程方式断开我的android应用程序中的耳机连接 [英] media player should stop on disconnecting headphone in my android app programatically

查看:40
本文介绍了媒体播放器应停止以编程方式断开我的android应用程序中的耳机连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发媒体播放器应用程序时遇到问题.
我想要它,以便当我从设备中卸下耳机时,应用程序中的MediaPlayer会暂停.

I have an issue in developing a media player application.
I want it so that when I remove my headphone from my device then the MediaPlayer in my app pauses.

推荐答案

Android文档建议使用AUDIO_BECOMING_NOISY意向过滤器

The Android documentation suggests using the AUDIO_BECOMING_NOISY intent filter

在意图中设置意图过滤器,然后:

Set the intent filter in your manafest and then:

public class MusicIntentReceiver extends android.content.BroadcastReceiver {
   @Override 
   public void onReceive(Context ctx, Intent intent) {
      if (intent.getAction().equals(
                    android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
          // signal your service to stop playback 
          // (via an Intent, for instance) 
      } 
   } 
} 

信息: http://developer.android.com/guide/topic/media/mediaplayer.html#noisyintent

这篇关于媒体播放器应停止以编程方式断开我的android应用程序中的耳机连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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