我的流式音频播​​放器继续在通话中发挥 - 不能使它停下来! (安卓) [英] My streaming audio player continues to play during a phone call - cannot make it stop! (Android)

查看:324
本文介绍了我的流式音频播​​放器继续在通话中发挥 - 不能使它停下来! (安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它由多个活动和一个服务。主要的活动是流式音频的UI。当用户按下播放按钮,启动服务,流音频和读取元数据。元数据,然后推到和用户界面,如果看到通知栏。一切都按预期直到一个电话进来,我本以为(我傻),通过使用标准的媒体播放器,机器人会处理的数据流和电话称自己之间切换音频。所以,我创建了一个PhoneStateListener处理来电,并根据需要停止我的球员。我做错了什么,虽然,因为它仍然是行不通的。如果你不介意看服务类,也许日志文件,我真的AP preciate了!

对不起一切都是那么冗长!

感谢您! 金大中

 包com.wtts.app;

进口java.io.BufferedInputStream中;
进口java.io.FilterInputStream中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.net.MalformedURLException;
进口的java.net.URL;
进口java.net.URLConnection中;
进口java.util.Timer中;
进口java.util.TimerTask中;

进口android.app.Notification;
进口android.app.NotificationManager;
进口android.app.PendingIntent;
进口android.app.Service;
进口android.content.BroadcastReceiver;
进口android.content.Context;
进口android.content.Intent;
进口android.content.IntentFilter;
进口android.graphics.Bitmap;
进口android.graphics.BitmapFactory;
进口android.media.AudioManager;
进口android.media.MediaPlayer;
进口android.os.IBinder;
进口android.telephony.PhoneStateListener;
进口android.telephony.TelephonyManager;
进口android.util.Log;

公共类WttsListenService延伸服务{

 私人字符串txtArtist =;
 私人字符串txtTitle =;
 私人字符串txtAlbum =;
 私人位图bmAlbum;
 私人字符串lastSong =一个;
 的String [] MDATA =新的String [3];
 布尔IS_PLAYING;
 布尔阻断;

 公共URL streamUrl = NULL;
 字符串URL =htt​​p://customchannels-audio.streamguys.com/wttsfm-mp3;

 公共静态最后弦乐UPDATE_SONG =com.wtts.custom.intent.action.UPDATE_SONG;
 私人定时器定时=新的Timer();
 私有静态最后长的更新周期= 8500;

 公共静态最后弦乐PHONE_STATE =android.intent.action.PHONE_STATE;
 IntentFilter的过滤器;
 BroadcastReceiver的接收器;

 的MediaPlayer播放器=新的MediaPlayer();

 私人NotificationManager处;
 私人诠释NOTIFICATION_ID = 10101;

 公共静态最后弦乐SHOW_PROGRESS =com.wtts.custom.intent.action.SHOW_PROGRESS;

 @覆盖
 公众的IBinder onBind(意向意图){
  返回null;
 }

 @覆盖
 公共无效的onCreate(){
  super.onCreate();
  Log.i(this.toString(),的onCreate);

  过滤器=新的IntentFilter(PHONE_STATE);
  接收器=新ServiceReceiver();
  registerReceiver(接收机,过滤器);

  如果(玩家!= NULL){
   player.reset();
   player.release();
   球员= NULL;
  }
  startPlaying();
 }

 无效startPlaying(){
  Log.i(this.toString(),startPlaying);

  尝试 {
   球员=新的MediaPlayer();
   player.setDataSource(URL);
   player.setAudioStreamType(AudioManager.STREAM_MUSIC);
   播放器prepare()。
   player.setOn preparedListener(新MediaPlayer.On preparedListener(){
    @覆盖
    公共无效于prepared(MediaPlayer的播放器){
     // TODO自动生成方法存根
     player.start();
     的UpdateProgress(PLAY);
    }
   });
  }赶上(例外五){
   Log.e(的getClass()getSimpleName(),打造媒体播放器失败,E);
   player.reset();
   player.release();
   球员= NULL;
   的UpdateProgress(失败);
   返回;
  }

  timer.scheduleAtFixedRate(新的TimerTask(){
   公共无效的run(){
    尝试 {
     的getMetaData();
     视频下载(更新周期​​);
    }赶上(InterruptedException的IE){
     Log.e(的getClass()。getSimpleName(),
       MetadataService中InterruptedException的
         + ie.toString());
    }
   }
  },0,更新周期);

 }

 空向notifyUser(){
  Log.i(this.toString(),向notifyUser);
  纳米=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

  通知注=新的通知(R.drawable.wttsicon,92.3 WTTS
    System.currentTimeMillis的());

  PendingIntent意图= PendingIntent.getActivity(此,0,新的意向(
    此,WttsApp.class),0);
  字符串STRA =92.3 WTTS;
  字符串STRB =实时流;
  如果(txtArtist!=){
   STRA = txtTitle;
  }
  如果(txtTitle!=){
   STRB = txtArtist;
  }
  note.setLatestEventInfo(这一点,STRA,STRB,意图);
  nm.notify(NOTIFICATION_ID,请注意);

 }

 @覆盖
 公共无效的onDestroy(){
  Log.i(this.toString(),的onDestroy);
  super.onDestroy();
  如果(定时器!= NULL){
   timer.cancel();
  }
  如果(NM!= NULL){
   nm.cancel(NOTIFICATION_ID);
  }
  如果(玩家!= NULL){
   player.stop();
   player.release();
  }
  unregisterReceiver(接收机);
 }

 私人无效的UpdateProgress(字符串州){
  意向意图;
  尝试 {
   意图=新的意图(SHOW_PROGRESS);
   intent.putExtra(状态,状态);
   sendBroadcast(意向);
  }赶上(例外五){
   Log.e(的getClass()。getSimpleName(),
     sendBroadcast失败 - 停止微调,E);
   意图= NULL;
  }
  意图= NULL;
 }

 公共类ServiceReceiver扩展的BroadcastReceiver {
  @覆盖
  公共无效的onReceive(上下文的背景下,意图意图){
   尝试 {
    MyPhoneStateListener phoneListener =新MyPhoneStateListener();
    TelephonyManager电话=(TelephonyManager)上下文
      .getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener,
      PhoneStateListener.LISTEN_CALL_STATE);
   }赶上(例外五){
    Log.i(异常,ServiceReceiver()E =+ E);
   }
  }
 }

 公共类MyPhoneStateListener扩展PhoneStateListener {
  公共无效onCallStateChanged(INT状态,串incomingNumber){
   尝试 {
    开关(州){
    案例TelephonyManager.CALL_STATE_RINGING:
     Log.i(电话经理,手机状态=+状态);
     如果(IS_PLAYING){
      阻断= TRUE;
      的UpdateProgress(STOP);
      player.setAudioStreamType(AudioManager.AUDIOFOCUS_LOSS);
      // player.stop();
     }
     打破;
    案例TelephonyManager.CALL_STATE_OFFHOOK:
     Log.i(电话经理,手机状态=+状态);
     打破;
    案例TelephonyManager.CALL_STATE_IDLE:
     Log.i(电话经理,手机状态=+状态);
     如果(间断){
      阻断= FALSE;
      player.setAudioStreamType(AudioManager.AUDIOFOCUS_GAIN);
      // player.start();
      的UpdateProgress(PLAY);
     }
     打破;
    }
   }赶上(例外五){
    Log.i(异常,PhoneStateListener()E =+ E);
   }
  }
 };

 私人无效的getMetaData(){
  尝试 {
   streamUrl =新的URL(网址);
  }赶上(MalformedURLException异常E){
   e.printStackTrace();
  }
  IcyStreamMeta streamMeta = NULL;
  尝试 {
   streamMeta =新IcyStreamMeta(streamUrl);
   尝试 {
    streamMeta.refreshMeta();
    bmAlbum = NULL;
    尝试 {
     MDATA = streamMeta.getSongInfo();

     txtArtist = MDATA [0];
     txtTitle = MDATA [1];
     txtAlbum = MDATA [2];

    }赶上(例外五){
     Log.e(this.toString(),MDATA = streamMeta错误,E);
     txtArtist =;
     txtTitle =;
     txtAlbum =;
    }
   }赶上(IOException异常E){
    Log.e(的getClass()。getSimpleName(),
      streamMeta.refreshMeta错误,E);
   }
  }赶上(例外五){
   e.printStackTrace();
  }
  字符串thisSong = txtArtist + txtTitle + txtAlbum;
  如果(thisSong.equals(lastSong)){
   // 没做什么
  } 其他 {
   如果(txtAlbum ==){
   }否则,如果(txtAlbum == NULL){
   } 其他 {
    bmAlbum = findImage();
   }
   submitSong();
   lastSong = txtArtist + txtTitle + txtAlbum;
  }
 }

 公共无效submitSong(){
  Log.i(this.toString(),submitSong);
  意向意图=新的意图(UPDATE_SONG);
  intent.putExtra(艺术家,txtArtist);
  intent.putExtra(标题,txtTitle);
  intent.putExtra(相册,txtAlbum);
  intent.putExtra(bmAlbum,bmAlbum);
  尝试 {
   sendBroadcast(意向);
  }赶上(例外五){
   Log.e(的getClass()getSimpleName(),sendBroadcast失败,例如);
  }
  向notifyUser();
 }

 位图findImage(){
  Log.i(this.toString(),findImage);
  URL fullUrl = NULL;
  字符串tempAlbum = txtAlbum;
  tempAlbum = tempAlbum.replaceAll(,_);
  字符串IMAGEURL =的getString(R.string.imageurl)+ tempAlbum
    +的getString(R.string.imageformat);
  IMAGEURL = imageUrl.replaceAll(\ N,);

  尝试 {
   fullUrl =新的URL(IMAGEURL);
  }赶上(MalformedURLException异常E){
   // TODO自动生成的catch块
   // Log.i(的getClass()getSimpleName(),IMAGEURL未设置。);
   e.printStackTrace();
   返回null;
  }

  尝试 {
   最后的URLConnection康恩= fullUrl.openConnection();
   conn.connect();
   最后的BufferedInputStream双=新的BufferedInputStream(
     新FlushedInputStream(conn.getInputStream()));
   bmAlbum = BitmapFactory.de codeStream(之二);
   bis.close();
   返回bmAlbum;
  }赶上(IOException异常E){
   Log.d(的getClass()getSimpleName(),专辑图片未设定);
  }
  返回null;
 }

 / *
  *该跳过字节的确切数目的InputStream提供的,除非它
  *达到EOF。
  * /
 静态类FlushedInputStream扩展FilterInputStream中的{
  公共FlushedInputStream(InputStream中的InputStream){
   超(InputStream的);
  }

  @覆盖
  众长跳跃(N久)抛出IOException异常{
   长totalBytesSkipped = 0L;
   而(totalBytesSkipped n种){
    长bytesSkipped = in.skip(N  -  totalBytesSkipped);
    如果(bytesSkipped == 0L){
     INT B =阅读();
     如果(b将0){
      打破; //我们到达EOF
     } 其他 {
      bytesSkipped = 1; //我们读到一个字节
     }
    }
    totalBytesSkipped + = bytesSkipped;
   }
   返回totalBytesSkipped;
  }
 }
}
 

LogCat中输出:

  01-28 16:35:40.487:INFO/com.wtts.app.IcyStreamMeta@43fea268(274):{StreamTitle =珍珠果酱〜黑色〜十
01-28 16:35:40.487:INFO/com.wtts.app.IcyStreamMeta@43fea268(274):〜334000〜Š~~~~ 5:34〜史诗}
01-28 16:35:40.487:INFO/com.wtts.app.IcyStreamMeta@43fea268(274):getSongInfo
01-28 16:35:40.497:INFO/com.wtts.app.IcyStreamMeta@43fea268(274):返回MDATA
01-28 16:35:40.570:WARN / AudioFlinger(33):写阻塞85毫秒,476延迟写入,螺纹0xb3f0
01-28 16:35:45.597:WARN / AudioFlinger(33):写阻塞80毫秒,522延迟写入,螺纹0xb3f0
01-28 16:35:48.987:从AudioFocus_For_Phone_Ring_And_Calls AudioFocus requestAudioFocus():查看/ AudioService(58)
01-28 16:35:49.067:信息/电话管理器(274):手机状态= 1
01-28 16:35:49.077:DEBUG / CallNotifier(125):正在响铃...(新)
01-28 16:35:49.097:DEBUG / CallNotifier(125):onNewRingingConnection():来电:真实状态:传入拨号后状态:NOT_STARTED
01-28 16:35:49.567:DEBUG /振铃(125):环()...
01-28 16:35:49.677:DEBUG /振铃(125):mRingHandler:PLAY_RING_ONCE ...
01-28 16:35:49.677:DEBUG /振铃(125):创建铃声:内容://设置/系统/铃声
01-28 16:35:49.837:信息/ ActivityManager(58):启动活动:意向{行动= android.intent.action.MAIN FLG = 0x10840000 CMP = com.android.phone / .InCallScreen}
01-28 16:35:50.157:DEBUG / MediaPlayer的(125):可能在客户端无法打开文件,试图服务器端
01-28 16:35:50.317:DEBUG / PhoneWindow(274):没能挽救其观点着眼,因为细致地查看com.android.internal.policy.impl.PhoneWindow$DecorView@43e47b58没有身份证。
01-28 16:35:50.357:ERROR / MediaPlayerService(33):无法打开FD内容://设置/系统/铃声
01-28 16:35:50.357:ERROR / MediaPlayer的(125):无法创建媒体播放器
01-28 16:35:50.367:ERROR / RingtoneManager(125):未能打开铃声的内容://设置/系统/铃声
01-28 16:35:50.647:DEBUG / InCallScreen(125):的onCreate()...这= com.android.phone.InCallScreen@43ecc0e0
01-28 16:35:51.817:WARN /的ResourceType(125):getEntry失败,因为entryIndex 65超出类型entryCount 1
01-28 16:35:52.147:DEBUG / dalvikvm(125):GC_FOR_MALLOC释放5482对象/在140ms的312040字节
01-28 16:35:52.837:DEBUG / InCallScreen(125):initInCallTouchUi()...
01-28 16:35:52.847:DEBUG / ManageConferenceUtils(125):ManageConferenceUtils构造...
01-28 16:35:52.847:调试/ InCallScreen(125): - 使用SlidingDrawer基于拨号盘。找到dialerView:com.android.phone.DTMFTwelveKeyDialerView@43edf870
01-28 16:35:52.867:DEBUG / InCallScreen(125):...和SlidingDrawer:android.widget.SlidingDrawer@43edb1f8
01-28 16:35:52.887:DEBUG / InCallScreen(125):的onCreate():这是我们的第一个启动,检查目的...
01-28 16:35:52.887:DEBUG / InCallScreen(125):internalResolveIntent:动作= android.intent.action.MAIN
01-28 16:35:52.897:DEBUG / InCallScreen(125):的onCreate():mInCallInitialStatus =成功
01-28 16:35:52.917:DEBUG / InCallScreen(125):的onCreate():退出
01-28 16:35:52.917:DEBUG / InCallScreen(125):onResume()...
01-28 16:35:52.937:DEBUG / PhoneApp(125):关闭状态栏
01-28 16:35:52.937:调试/ PhoneApp(125):StatusBarManager.DISABLE_EXPAND
01-28 16:35:52.947:DEBUG /状态栏(58):DISABLE_EXPAND:是
01-28 16:35:53.047:DEBUG / InCallScreen(125): -  onResume:初始状态=成功
01-28 16:35:53.047:DEBUG / InCallScreen(125):setInCallScreenMode:NORMAL
01-28 16:35:53.077:DEBUG / InCallScreen(125):syncWithPhoneState()...
01-28 16:35:53.077:调试/ PhoneUtils(125):dumpCallState():
01-28 16:35:53.087:DEBUG / PhoneUtils(125): - 电话:处理器{43e79ba8},名称= GSM,状态= RINGING
01-28 16:35:53.087:DEBUG / PhoneUtils(125): -  FG电话:空闲的isAlive假isRinging假isDialing假isIdle真hasConnections假
01-28 16:35:53.087:DEBUG / PhoneUtils(125): -  BG电话:空闲的isAlive假isRinging假isDialing假isIdle真hasConnections假
01-28 16:35:53.087:DEBUG / PhoneUtils(125): - 振铃呼叫:传入的isAlive真正isRinging真isDialing假isIdle假hasConnections真
01-28 16:35:53.087:DEBUG / PhoneUtils(125): -  hasRingingCall真hasActiveCall假hasHoldingCall假allLinesTaken假
01-28 16:35:53.107:DEBUG / PhoneUtils(125): - 振铃状态:假的
01-28 16:35:53.107:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:35:53.127:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:35:53.237:DEBUG / InCallScreen(125):dismissAllDialogs()...
01-28 16:35:53.237:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:35:53.257:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn = TRUE(真isRinging,isDialing假,showingDisc假)
01-28 16:35:53.357:DEBUG / InCallScreen(125):onPhoneStateChanged()...
01-28 16:35:53.357:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:35:53.407:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:35:53.467:DEBUG / InCallScreen(125):dismissAllDialogs()...
01-28 16:35:53.467:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:35:53.477:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn = TRUE(真isRinging,isDialing假,showingDisc假)
01-28 16:35:53.877:WARN / InputManagerService(58):对非重点客户com.android.internal.view.IInputMethodClient$Stub$Proxy@43f3e628开始输入(UID = 10036 PID = 274)
01-28 16:35:54.107:信息/ ActivityManager(58):显示活动com.android.phone / .InCallScreen:3613毫秒(共3613毫秒)
01-28 16:35:54.187:信息/ ARMAssembler(58):产生scanline__00000177:03010104_00000001_00000000 [44 IPP](66英寸),在[0x333318:0x333420]在6539073 NS
01-28 16:35:57.857:INFO/com.wtts.app.IcyStreamMeta@43ed1820(274):{StreamTitle =珍珠果酱〜黑色〜十
01-28 16:35:57.857:INFO/com.wtts.app.IcyStreamMeta@43ed1820(274):〜334000〜Š~~~~ 5:34〜史诗}
01-28 16:35:57.857:INFO/com.wtts.app.IcyStreamMeta@43ed1820(274):getSongInfo
01-28 16:35:57.867:INFO/com.wtts.app.IcyStreamMeta@43ed1820(274):返回MDATA
01-28 16:35:57.947:WARN / AudioFlinger(33):写阻塞88毫秒,557延迟写入,螺纹0xb3f0
01-28 16:35:59.797:DEBUG / dalvikvm(130):GC_EXPLICIT释放1200对象/在368ms 86592字节
01-28 16:36:02.951:WARN / AudioFlinger(33):写阻塞76毫秒,600延迟写入,螺纹0xb3f0
01-28 16:36:05.347:WARN /的ResourceType(125):试图挽回袋0x01010041这是无效的,或在一个周期。
01-28 16:36:05.417:DEBUG / InCallTouchUi(125):onDialTrigger(whichHandle = 1)...
01-28 16:36:05.417:DEBUG / InCallScreen(125):handleOnscreenButtonClick(编号2131099670)...
01-28 16:36:05.437:DEBUG / InCallScreen(125):internalAnswerCall:回答...
01-28 16:36:05.437:DEBUG /振铃(125):stopRing()...
01-28 16:36:05.477:DEBUG /振铃(125):mRingHandler:STOP_RING ...
01-28 16:36:05.477:DEBUG /振铃(125): -  STOP_RING与空铃声!味精= {么= 3时= 304812}
01-28 16:36:05.508:信息/电话(125):acceptCall:来电...
01-28 16:36:05.558:DEBUG / AudioHardwareInterface(33):setMode(IN_CALL)
01-28 16:36:05.568:DEBUG / dalvikvm(58):GREF已增至301
01-28 16:36:05.607:DEBUG / InCallTouchUi(125):updateState:太快了最后一个动作后,没有图纸!
01-28 16:36:05.897:DEBUG / dalvikvm(125):GC_EXTERNAL_ALLOC释放2894对象/在137ms 169384字节
01-28 16:36:06.217:从AudioFocus_For_Phone_Ring_And_Calls AudioFocus requestAudioFocus():查看/ AudioService(58)
01-28 16:36:06.308:DEBUG / CallNotifier(125):stopRing()...(摘机状态)
01-28 16:36:06.308:DEBUG /振铃(125):stopRing()...
01-28 16:36:06.337:DEBUG /振铃(125): -  stopRing:空mRingHandler!
01-28 16:36:06.438:DEBUG / InCallScreen(125):onPhoneStateChanged()...
01-28 16:36:06.438:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:36:06.457:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:36:06.508:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:36:06.508:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn =假(isR​​inging假,isDialing假,showingDisc假)
01-28 16:36:07.048:信息/电话管理器(274):手机状态= 2
01-28 16:36:07.158:信息/电话管理器(274):手机状态= 2
01-28 16:36:07.358:DEBUG / dalvikvm(157):GC_EXPLICIT释放2275对象/在1656ms 127704字节
01-28 16:36:07.437:信息/ ActivityManager(58):过程android.process.acore(PID 157)已经死亡。
01-28 16:36:10.438:DEBUG / dalvikvm(274):GC_FOR_MALLOC释放38735对象/ 957792字节151ms
01-28 16:36:11.838:INFO/com.wtts.app.IcyStreamMeta@43e887b0(274):{StreamTitle =珍珠果酱〜黑色〜十
01-28 16:36:11.838:INFO/com.wtts.app.IcyStreamMeta@43e887b0(274):〜334000〜Š~~~~ 5:34〜史诗}
01-28 16:36:11.838:INFO/com.wtts.app.IcyStreamMeta@43e887b0(274):getSongInfo
01-28 16:36:11.848:INFO/com.wtts.app.IcyStreamMeta@43e887b0(274):返回MDATA
01-28 16:36:11.938:WARN / AudioFlinger(33):写阻塞107毫秒,621延迟写入,螺纹0xb3f0
01-28 16:36:16.968:WARN / AudioFlinger(33):写阻塞74毫秒,666延迟写入,螺纹0xb3f0
01-28 16:36:21.167:DEBUG / CallNotifier(125):stopRing()...(摘机状态)
01-28 16:36:21.167:DEBUG /振铃(125):stopRing()...
01-28 16:36:21.217:DEBUG /振铃(125): -  stopRing:空mRingHandler!
01-28 16:36:21.297:DEBUG / InCallScreen(125):onPhoneStateChanged()...
01-28 16:36:21.297:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:36:21.297:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:36:21.328:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:36:21.328:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn =真(isRinging假,isDialing假,showingDisc真)
01-28 16:36:21.477:信息/电话管理器(274):手机状态= 0
01-28 16:36:21.527:信息/电话管理器(274):手机状态= 0
01-28 16:36:21.577:从AudioFocus_For_Phone_Ring_And_Calls AudioFocus abandonAudioFocus():查看/ AudioService(58)
01-28 16:36:21.707:DEBUG / CallNotifier(125):断开
01-28 16:36:21.707:DEBUG / CallNotifier(125): -  onDisconnect:病因=本地,来料= TRUE,日期= 1296250548953
01-28 16:36:21.727:DEBUG / CallNotifier(125):stopRing()...(onDisconnect)
01-28 16:36:21.727:DEBUG /振铃(125):stopRing()...
01-28 16:36:21.747:DEBUG /振铃(125): -  stopRing:空mRingHandler!
01-28 16:36:21.797:DEBUG / CallNotifier(125): -  onDisconnect():LogNumber日志设置为:1231234
01-28 16:36:21.797:DEBUG / CallNotifier(125): - 获得presentation():忽略连接的presentation:1
01-28 16:36:21.837:DEBUG / CallNotifier(125): - 获得presentation:presentation:1
01-28 16:36:21.937:DEBUG / InCallScreen(125):onDisconnect:来电:真实状态:DISCONNECTED拨号后状态:NOT_STARTED,原因=本地
01-28 16:36:21.947:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:36:21.967:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:36:21.987:DEBUG / InCallScreen(125):setInCallScreenMode:CALL_ENDED
01-28 16:36:21.987:WARN / KeyCharacterMap(125):没有键盘ID 0
01-28 16:36:22.017:WARN / KeyCharacterMap(125):使用默认的键盘对应:/system/usr/keychars/qwerty.kcm.bin
01-28 16:36:22.077:信息/电话管理器(274):手机状态= 0
01-28 16:36:22.237:DEBUG / InCallScreen(125): -  delayedCleanupAfterDisconnect:电话空闲时...
01-28 16:36:22.237:DEBUG / InCallScreen(125): -  delayedCleanupAfterDisconnect:整理InCallScreen ...
01-28 16:36:22.257:DEBUG / InCallScreen(125):endInCallScreenSession()...
01-28 16:36:22.268:信息/ ActivityManager(58):moveTaskToBack:4
01-28 16:36:22.297:DEBUG / InCallScreen(125):setInCallScreenMode:UNDEFINED
01-28 16:36:22.337:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:36:22.337:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn =假(isR​​inging假,isDialing假,showingDisc假)
01-28 16:36:22.357:DEBUG / AudioHardwareInterface(33):setMode(NORMAL)
01-28 16:36:22.397:DEBUG / InCallScreen(125):onPhoneStateChanged()...
01-28 16:36:22.407:DEBUG / InCallScreen(125):updateScreen()...
01-28 16:36:22.417:DEBUG / InCallScreen(125): -  updateScreen:更新在通话界面...
01-28 16:36:22.427:DEBUG / PhoneApp(125):updateWakeState:callscreen真,拨号错误,扬声器假...
01-28 16:36:22.427:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn =假(isR​​inging假,isDialing假,showingDisc假)
01-28 16:36:22.457:DEBUG / InCallScreen(125):在onPause()...
01-28 16:36:22.467:DEBUG / InCallScreen(125):dismissAllDialogs()...
01-28 16:36:22.497:DEBUG / PhoneApp(125):重新启用状态栏
01-28 16:36:22.497:DEBUG / PhoneApp(125):StatusBarManager.DISABLE_NONE
01-28 16:36:22.517:DEBUG / PhoneApp(125):updateWakeState:callscreen假,拨号错误,扬声器假...
01-28 16:36:22.527:DEBUG / PhoneApp(125):updateWakeState:keepScreenOn =假(isR​​inging假,isDialing假,showingDisc假)
01-28 16:36:22.997:信息/ ActivityManager(58):启动PROC android.process.acore为内容提供商com.android.providers.contacts / .CallLogProvider:PID = 295的uid = 10000导报= {3003,1015}
01-28 16:36:23.427:DEBUG / InCallScreen(125):的onStop()...
01-28 16:36:23.427:DEBUG / InCallScreen(125):的onStop:状态= IDLE
01-28 16:36:24.247:信息/ ActivityThread(295):发布商com.android.social:com.android.providers.contacts.SocialProvider
01-28 16:36:24.527:信息/ ActivityThread(295):发布商的应用:com.android.providers.applications.ApplicationsProvider
01-28 16:36:25.197:信息/ ActivityThread(295):发布商的联系; com.android.contacts:com.android.providers.contacts.ContactsProvider2
01-28 16:36:27.367:信息/ ActivityThread(295):发布商call_log:com.android.providers.contacts.CallLogProvider
01-28 16:36:27.417:信息/ ActivityThread(295):发布商user_dictionary:com.android.providers.userdictionary.UserDictionaryProvider
01-28 16:36:30.147:信息/ ActivityManager(58):过程com.android.mms(PID 207)已经死亡。
01-28 16:36:30.257:INFO/com.wtts.app.IcyStreamMeta@43f45030(274):{StreamTitle =珍珠果酱〜黑色〜十
01-28 16:36:30.257:INFO/com.wtts.app.IcyStreamMeta@43f45030(274):〜334000〜Š~~~~ 5:34〜史诗}
01-28 16:36:30.257:INFO/com.wtts.app.IcyStreamMeta@43f45030(274):getSongInfo
01-28 16:36:30.277:INFO/com.wtts.app.IcyStreamMeta@43f45030(274):返回MDATA
01-28 16:36:30.707:WARN / AudioFlinger(33):写阻塞86毫秒,704延迟写入,螺纹0xb3f0
01-28 16:36:35.727:WARN / AudioFlinger(33):写阻塞73毫秒,746延迟写入,螺纹0xb3f0
01-28 16:36:43.327:DEBUG / dalvikvm(274):GC_FOR_MALLOC释放37781对象/ 927336字节191ms
01-28 16:36:43.767:INFO/com.wtts.app.IcyStreamMeta@43f123e8(274):{StreamTitle =珍珠果酱〜黑色〜十
01-28 16:36:43.767:INFO/com.wtts.app.IcyStreamMeta@43f123e8(274):〜334000〜Š~~~~ 5:34〜史诗}
01-28 16:36:43.767:INFO/com.wtts.app.IcyStreamMeta@43f123e8(274):getSongInfo
 

解决方案

您需要管理音频设备在通话期间停止音乐。

检查了这一点: http://developer.android.com/培训/管理音频/音频focus.html

I have an app that consists of multiple activities and one service. The primary activity is a UI for streaming audio. When the user pushes the play button, the service is started, streaming the audio and reading metadata. The metadata is then pushed to the UI if visible and the Notification Bar. Everything functions as expected until a phone call comes in. I had assumed (silly me) that by using the standard media player, android would handle switching audio between the stream and phone call itself. So I created a PhoneStateListener to handle the calls and stop my player as needed. I've done something wrong though, because it still isn't working. If you wouldn't mind looking at the service class and perhaps the log files, I'd really appreciate it!

Sorry everything is so verbose!

Thank you! Dae

package com.wtts.app;

import java.io.BufferedInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Timer;
import java.util.TimerTask;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class WttsListenService extends Service {

 private String txtArtist = "";
 private String txtTitle = "";
 private String txtAlbum = "";
 private Bitmap bmAlbum;
 private String lastSong = "a";
 String[] mData = new String[3];
 boolean IS_PLAYING;
 boolean INTERRUPTED;

 public URL streamUrl = null;
 String url = "http://customchannels-audio.streamguys.com/wttsfm-mp3";

 public static final String UPDATE_SONG = "com.wtts.custom.intent.action.UPDATE_SONG";
 private Timer timer = new Timer();
 private static final long UPDATE_INTERVAL = 8500;

 public static final String PHONE_STATE = "android.intent.action.PHONE_STATE";
 IntentFilter filter;
 BroadcastReceiver receiver;

 MediaPlayer player = new MediaPlayer();

 private NotificationManager nm;
 private int NOTIFICATION_ID = 10101;

 public static final String SHOW_PROGRESS = "com.wtts.custom.intent.action.SHOW_PROGRESS";

 @Override
 public IBinder onBind(Intent intent) {
  return null;
 }

 @Override
 public void onCreate() {
  super.onCreate();
  Log.i(this.toString(), "onCreate");

  filter = new IntentFilter(PHONE_STATE);
  receiver = new ServiceReceiver();
  registerReceiver(receiver, filter);

  if (player != null) {
   player.reset();
   player.release();
   player = null;
  }
  startPlaying();
 }

 void startPlaying() {
  Log.i(this.toString(), "startPlaying");

  try {
   player = new MediaPlayer();
   player.setDataSource(url);
   player.setAudioStreamType(AudioManager.STREAM_MUSIC);
   player.prepare();
   player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer player) {
     // TODO Auto-generated method stub
     player.start();
     updateProgress("PLAY");
    }
   });
  } catch (Exception e) {
   Log.e(getClass().getSimpleName(), "create media player failed", e);
   player.reset();
   player.release();
   player = null;
   updateProgress("FAIL");
   return;
  }

  timer.scheduleAtFixedRate(new TimerTask() {
   public void run() {
    try {
     getMetadata();
     Thread.sleep(UPDATE_INTERVAL);
    } catch (InterruptedException ie) {
     Log.e(getClass().getSimpleName(),
       "MetadataService InterruptedException "
         + ie.toString());
    }
   }
  }, 0, UPDATE_INTERVAL);

 }

 void notifyUser() {
  Log.i(this.toString(), "notifyUser");
  nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

  Notification note = new Notification(R.drawable.wttsicon, "92.3 WTTS",
    System.currentTimeMillis());

  PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(
    this, WttsApp.class), 0);
  String strA = "92.3 WTTS";
  String strB = "Live Stream";
  if (txtArtist != "") {
   strA = txtTitle;
  }
  if (txtTitle != "") {
   strB = txtArtist;
  }
  note.setLatestEventInfo(this, strA, strB, intent);
  nm.notify(NOTIFICATION_ID, note);

 }

 @Override
 public void onDestroy() {
  Log.i(this.toString(), "onDestroy");
  super.onDestroy();
  if (timer != null) {
   timer.cancel();
  }
  if (nm != null) {
   nm.cancel(NOTIFICATION_ID);
  }
  if (player != null) {
   player.stop();
   player.release();
  }
  unregisterReceiver(receiver);
 }

 private void updateProgress(String state) {
  Intent intent;
  try {
   intent = new Intent(SHOW_PROGRESS);
   intent.putExtra("state", state);
   sendBroadcast(intent);
  } catch (Exception e) {
   Log.e(getClass().getSimpleName(),
     "sendBroadcast failed - stop spinner", e);
   intent = null;
  }
  intent = null;
 }

 public class ServiceReceiver extends BroadcastReceiver {
  @Override
  public void onReceive(Context context, Intent intent) {
   try {
    MyPhoneStateListener phoneListener = new MyPhoneStateListener();
    TelephonyManager telephony = (TelephonyManager) context
      .getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener,
      PhoneStateListener.LISTEN_CALL_STATE);
   } catch (Exception e) {
    Log.i("Exception", "ServiceReceiver() e = " + e);
   }
  }
 }

 public class MyPhoneStateListener extends PhoneStateListener {
  public void onCallStateChanged(int state, String incomingNumber) {
   try {
    switch (state) {
    case TelephonyManager.CALL_STATE_RINGING:
     Log.i("Telephony Manager", "phone state=" + state);
     if (IS_PLAYING) {
      INTERRUPTED = true;
      updateProgress("STOP");
      player.setAudioStreamType(AudioManager.AUDIOFOCUS_LOSS);
      // player.stop();
     }
     break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
     Log.i("Telephony Manager", "phone state=" + state);
     break;
    case TelephonyManager.CALL_STATE_IDLE:
     Log.i("Telephony Manager", "phone state=" + state);
     if (INTERRUPTED) {
      INTERRUPTED = false;
      player.setAudioStreamType(AudioManager.AUDIOFOCUS_GAIN);
      // player.start();
      updateProgress("PLAY");
     }
     break;
    }
   } catch (Exception e) {
    Log.i("Exception", "PhoneStateListener() e = " + e);
   }
  }
 };

 private void getMetadata() {
  try {
   streamUrl = new URL(url);
  } catch (MalformedURLException e) {
   e.printStackTrace();
  }
  IcyStreamMeta streamMeta = null;
  try {
   streamMeta = new IcyStreamMeta(streamUrl);
   try {
    streamMeta.refreshMeta();
    bmAlbum = null;
    try {
     mData = streamMeta.getSongInfo();

     txtArtist = mData[0];
     txtTitle = mData[1];
     txtAlbum = mData[2];

    } catch (Exception e) {
     Log.e(this.toString(), "mData = streamMeta error", e);
     txtArtist = "";
     txtTitle = "";
     txtAlbum = "";
    }
   } catch (IOException e) {
    Log.e(getClass().getSimpleName(),
      "streamMeta.refreshMeta error", e);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  String thisSong = txtArtist + txtTitle + txtAlbum;
  if (thisSong.equals(lastSong)) {
   // do nothing
  } else {
   if (txtAlbum == "") {
   } else if (txtAlbum == null) {
   } else {
    bmAlbum = findImage();
   }
   submitSong();
   lastSong = txtArtist + txtTitle + txtAlbum;
  }
 }

 public void submitSong() {
  Log.i(this.toString(), "submitSong");
  Intent intent = new Intent(UPDATE_SONG);
  intent.putExtra("Artist", txtArtist);
  intent.putExtra("Title", txtTitle);
  intent.putExtra("Album", txtAlbum);
  intent.putExtra("bmAlbum", bmAlbum);
  try {
   sendBroadcast(intent);
  } catch (Exception e) {
   Log.e(getClass().getSimpleName(), "sendBroadcast failed", e);
  }
  notifyUser();
 }

 Bitmap findImage() {
  Log.i(this.toString(), "findImage");
  URL fullUrl = null;
  String tempAlbum = txtAlbum;
  tempAlbum = tempAlbum.replaceAll(" ", "_");
  String imageUrl = getString(R.string.imageurl) + tempAlbum
    + getString(R.string.imageformat);
  imageUrl = imageUrl.replaceAll("\n", "");

  try {
   fullUrl = new URL(imageUrl);
  } catch (MalformedURLException e) {
   // TODO Auto-generated catch block
   // Log.i(getClass().getSimpleName(), "imageUrl not set");
   e.printStackTrace();
   return null;
  }

  try {
   final URLConnection conn = fullUrl.openConnection();
   conn.connect();
   final BufferedInputStream bis = new BufferedInputStream(
     new FlushedInputStream(conn.getInputStream()));
   bmAlbum = BitmapFactory.decodeStream(bis);
   bis.close();
   return bmAlbum;
  } catch (IOException e) {
   Log.d(getClass().getSimpleName(), "album image not set");
  }
  return null;
 }

 /*
  * An InputStream that skips the exact number of bytes provided, unless it
  * reaches EOF.
  */
 static class FlushedInputStream extends FilterInputStream {
  public FlushedInputStream(InputStream inputStream) {
   super(inputStream);
  }

  @Override
  public long skip(long n) throws IOException {
   long totalBytesSkipped = 0L;
   while (totalBytesSkipped < n) {
    long bytesSkipped = in.skip(n - totalBytesSkipped);
    if (bytesSkipped == 0L) {
     int b = read();
     if (b < 0) {
      break; // we reached EOF
     } else {
      bytesSkipped = 1; // we read one byte
     }
    }
    totalBytesSkipped += bytesSkipped;
   }
   return totalBytesSkipped;
  }
 }
}

LogCat Output:

01-28 16:35:40.487: INFO/com.wtts.app.IcyStreamMeta@43fea268(274): {StreamTitle=Pearl Jam~Black~Ten
01-28 16:35:40.487: INFO/com.wtts.app.IcyStreamMeta@43fea268(274): ~334000~S~~~~5:34~Epic}
01-28 16:35:40.487: INFO/com.wtts.app.IcyStreamMeta@43fea268(274): getSongInfo
01-28 16:35:40.497: INFO/com.wtts.app.IcyStreamMeta@43fea268(274): return mData
01-28 16:35:40.570: WARN/AudioFlinger(33): write blocked for 85 msecs, 476 delayed writes, thread 0xb3f0
01-28 16:35:45.597: WARN/AudioFlinger(33): write blocked for 80 msecs, 522 delayed writes, thread 0xb3f0
01-28 16:35:48.987: INFO/AudioService(58):  AudioFocus  requestAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
01-28 16:35:49.067: INFO/Telephony Manager(274): phone state=1
01-28 16:35:49.077: DEBUG/CallNotifier(125): RINGING... (new)
01-28 16:35:49.097: DEBUG/CallNotifier(125): onNewRingingConnection():  incoming: true state: INCOMING post dial state: NOT_STARTED
01-28 16:35:49.567: DEBUG/Ringer(125): ring()...
01-28 16:35:49.677: DEBUG/Ringer(125): mRingHandler: PLAY_RING_ONCE...
01-28 16:35:49.677: DEBUG/Ringer(125): creating ringtone: content://settings/system/ringtone
01-28 16:35:49.837: INFO/ActivityManager(58): Starting activity: Intent { act=android.intent.action.MAIN flg=0x10840000 cmp=com.android.phone/.InCallScreen }
01-28 16:35:50.157: DEBUG/MediaPlayer(125): Couldn't open file on client side, trying server side
01-28 16:35:50.317: DEBUG/PhoneWindow(274): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@43e47b58 has no id.
01-28 16:35:50.357: ERROR/MediaPlayerService(33): Couldn't open fd for content://settings/system/ringtone
01-28 16:35:50.357: ERROR/MediaPlayer(125): Unable to to create media player
01-28 16:35:50.367: ERROR/RingtoneManager(125): Failed to open ringtone content://settings/system/ringtone
01-28 16:35:50.647: DEBUG/InCallScreen(125): onCreate()...  this = com.android.phone.InCallScreen@43ecc0e0
01-28 16:35:51.817: WARN/ResourceType(125): getEntry failing because entryIndex 65 is beyond type entryCount 1
01-28 16:35:52.147: DEBUG/dalvikvm(125): GC_FOR_MALLOC freed 5482 objects / 312040 bytes in 140ms
01-28 16:35:52.837: DEBUG/InCallScreen(125): initInCallTouchUi()...
01-28 16:35:52.847: DEBUG/ManageConferenceUtils(125): ManageConferenceUtils constructor...
01-28 16:35:52.847: DEBUG/InCallScreen(125): - Using SlidingDrawer-based dialpad.  Found dialerView: com.android.phone.DTMFTwelveKeyDialerView@43edf870
01-28 16:35:52.867: DEBUG/InCallScreen(125):   ...and the SlidingDrawer: android.widget.SlidingDrawer@43edb1f8
01-28 16:35:52.887: DEBUG/InCallScreen(125): onCreate(): this is our very first launch, checking intent...
01-28 16:35:52.887: DEBUG/InCallScreen(125): internalResolveIntent: action=android.intent.action.MAIN
01-28 16:35:52.897: DEBUG/InCallScreen(125): onCreate(): mInCallInitialStatus = SUCCESS
01-28 16:35:52.917: DEBUG/InCallScreen(125): onCreate(): exit
01-28 16:35:52.917: DEBUG/InCallScreen(125): onResume()...
01-28 16:35:52.937: DEBUG/PhoneApp(125): disable status bar
01-28 16:35:52.937: DEBUG/PhoneApp(125): StatusBarManager.DISABLE_EXPAND
01-28 16:35:52.947: DEBUG/StatusBar(58): DISABLE_EXPAND: yes
01-28 16:35:53.047: DEBUG/InCallScreen(125): - onResume: initial status = SUCCESS
01-28 16:35:53.047: DEBUG/InCallScreen(125): setInCallScreenMode: NORMAL
01-28 16:35:53.077: DEBUG/InCallScreen(125): syncWithPhoneState()...
01-28 16:35:53.077: DEBUG/PhoneUtils(125): dumpCallState():
01-28 16:35:53.087: DEBUG/PhoneUtils(125): - Phone: Handler{43e79ba8}, name = GSM, state = RINGING
01-28 16:35:53.087: DEBUG/PhoneUtils(125):   - FG call: IDLE isAlive false isRinging false isDialing false isIdle true hasConnections false
01-28 16:35:53.087: DEBUG/PhoneUtils(125):   - BG call: IDLE isAlive false isRinging false isDialing false isIdle true hasConnections false
01-28 16:35:53.087: DEBUG/PhoneUtils(125):   - RINGING call: INCOMING isAlive true isRinging true isDialing false isIdle false hasConnections true
01-28 16:35:53.087: DEBUG/PhoneUtils(125):   - hasRingingCall true hasActiveCall false hasHoldingCall false allLinesTaken false
01-28 16:35:53.107: DEBUG/PhoneUtils(125):   - Ringer state: false
01-28 16:35:53.107: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:35:53.127: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:35:53.237: DEBUG/InCallScreen(125): dismissAllDialogs()...
01-28 16:35:53.237: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:35:53.257: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = true (isRinging true, isDialing false, showingDisc false)
01-28 16:35:53.357: DEBUG/InCallScreen(125): onPhoneStateChanged()...
01-28 16:35:53.357: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:35:53.407: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:35:53.467: DEBUG/InCallScreen(125): dismissAllDialogs()...
01-28 16:35:53.467: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:35:53.477: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = true (isRinging true, isDialing false, showingDisc false)
01-28 16:35:53.877: WARN/InputManagerService(58): Starting input on non-focused client com.android.internal.view.IInputMethodClient$Stub$Proxy@43f3e628 (uid=10036 pid=274)
01-28 16:35:54.107: INFO/ActivityManager(58): Displayed activity com.android.phone/.InCallScreen: 3613 ms (total 3613 ms)
01-28 16:35:54.187: INFO/ARMAssembler(58): generated scanline__00000177:03010104_00000001_00000000 [ 44 ipp] (66 ins) at [0x333318:0x333420] in 6539073 ns
01-28 16:35:57.857: INFO/com.wtts.app.IcyStreamMeta@43ed1820(274): {StreamTitle=Pearl Jam~Black~Ten
01-28 16:35:57.857: INFO/com.wtts.app.IcyStreamMeta@43ed1820(274): ~334000~S~~~~5:34~Epic}
01-28 16:35:57.857: INFO/com.wtts.app.IcyStreamMeta@43ed1820(274): getSongInfo
01-28 16:35:57.867: INFO/com.wtts.app.IcyStreamMeta@43ed1820(274): return mData
01-28 16:35:57.947: WARN/AudioFlinger(33): write blocked for 88 msecs, 557 delayed writes, thread 0xb3f0
01-28 16:35:59.797: DEBUG/dalvikvm(130): GC_EXPLICIT freed 1200 objects / 86592 bytes in 368ms
01-28 16:36:02.951: WARN/AudioFlinger(33): write blocked for 76 msecs, 600 delayed writes, thread 0xb3f0
01-28 16:36:05.347: WARN/ResourceType(125): Attempt to retrieve bag 0x01010041 which is invalid or in a cycle.
01-28 16:36:05.417: DEBUG/InCallTouchUi(125): onDialTrigger(whichHandle = 1)...
01-28 16:36:05.417: DEBUG/InCallScreen(125): handleOnscreenButtonClick(id 2131099670)...
01-28 16:36:05.437: DEBUG/InCallScreen(125): internalAnswerCall: answering...
01-28 16:36:05.437: DEBUG/Ringer(125): stopRing()...
01-28 16:36:05.477: DEBUG/Ringer(125): mRingHandler: STOP_RING...
01-28 16:36:05.477: DEBUG/Ringer(125): - STOP_RING with null ringtone!  msg = { what=3 when=304812 }
01-28 16:36:05.508: INFO/phone(125): acceptCall: incoming...
01-28 16:36:05.558: DEBUG/AudioHardwareInterface(33): setMode(IN_CALL)
01-28 16:36:05.568: DEBUG/dalvikvm(58): GREF has increased to 301
01-28 16:36:05.607: DEBUG/InCallTouchUi(125): updateState: Too soon after last action; not drawing!
01-28 16:36:05.897: DEBUG/dalvikvm(125): GC_EXTERNAL_ALLOC freed 2894 objects / 169384 bytes in 137ms
01-28 16:36:06.217: INFO/AudioService(58):  AudioFocus  requestAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
01-28 16:36:06.308: DEBUG/CallNotifier(125): stopRing()... (OFFHOOK state)
01-28 16:36:06.308: DEBUG/Ringer(125): stopRing()...
01-28 16:36:06.337: DEBUG/Ringer(125): - stopRing: null mRingHandler!
01-28 16:36:06.438: DEBUG/InCallScreen(125): onPhoneStateChanged()...
01-28 16:36:06.438: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:36:06.457: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:36:06.508: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:36:06.508: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = false (isRinging false, isDialing false, showingDisc false)
01-28 16:36:07.048: INFO/Telephony Manager(274): phone state=2
01-28 16:36:07.158: INFO/Telephony Manager(274): phone state=2
01-28 16:36:07.358: DEBUG/dalvikvm(157): GC_EXPLICIT freed 2275 objects / 127704 bytes in 1656ms
01-28 16:36:07.437: INFO/ActivityManager(58): Process android.process.acore (pid 157) has died.
01-28 16:36:10.438: DEBUG/dalvikvm(274): GC_FOR_MALLOC freed 38735 objects / 957792 bytes in 151ms
01-28 16:36:11.838: INFO/com.wtts.app.IcyStreamMeta@43e887b0(274): {StreamTitle=Pearl Jam~Black~Ten
01-28 16:36:11.838: INFO/com.wtts.app.IcyStreamMeta@43e887b0(274): ~334000~S~~~~5:34~Epic}
01-28 16:36:11.838: INFO/com.wtts.app.IcyStreamMeta@43e887b0(274): getSongInfo
01-28 16:36:11.848: INFO/com.wtts.app.IcyStreamMeta@43e887b0(274): return mData
01-28 16:36:11.938: WARN/AudioFlinger(33): write blocked for 107 msecs, 621 delayed writes, thread 0xb3f0
01-28 16:36:16.968: WARN/AudioFlinger(33): write blocked for 74 msecs, 666 delayed writes, thread 0xb3f0
01-28 16:36:21.167: DEBUG/CallNotifier(125): stopRing()... (OFFHOOK state)
01-28 16:36:21.167: DEBUG/Ringer(125): stopRing()...
01-28 16:36:21.217: DEBUG/Ringer(125): - stopRing: null mRingHandler!
01-28 16:36:21.297: DEBUG/InCallScreen(125): onPhoneStateChanged()...
01-28 16:36:21.297: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:36:21.297: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:36:21.328: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:36:21.328: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = true (isRinging false, isDialing false, showingDisc true)
01-28 16:36:21.477: INFO/Telephony Manager(274): phone state=0
01-28 16:36:21.527: INFO/Telephony Manager(274): phone state=0
01-28 16:36:21.577: INFO/AudioService(58):  AudioFocus  abandonAudioFocus() from AudioFocus_For_Phone_Ring_And_Calls
01-28 16:36:21.707: DEBUG/CallNotifier(125): DISCONNECT
01-28 16:36:21.707: DEBUG/CallNotifier(125): - onDisconnect: cause = LOCAL, incoming = true, date = 1296250548953
01-28 16:36:21.727: DEBUG/CallNotifier(125): stopRing()... (onDisconnect)
01-28 16:36:21.727: DEBUG/Ringer(125): stopRing()...
01-28 16:36:21.747: DEBUG/Ringer(125): - stopRing: null mRingHandler!
01-28 16:36:21.797: DEBUG/CallNotifier(125): - onDisconnect(): logNumber set to: 1231234
01-28 16:36:21.797: DEBUG/CallNotifier(125): - getPresentation(): ignoring connection's presentation: 1
01-28 16:36:21.837: DEBUG/CallNotifier(125): - getPresentation: presentation: 1
01-28 16:36:21.937: DEBUG/InCallScreen(125): onDisconnect:  incoming: true state: DISCONNECTED post dial state: NOT_STARTED, cause=LOCAL
01-28 16:36:21.947: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:36:21.967: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:36:21.987: DEBUG/InCallScreen(125): setInCallScreenMode: CALL_ENDED
01-28 16:36:21.987: WARN/KeyCharacterMap(125): No keyboard for id 0
01-28 16:36:22.017: WARN/KeyCharacterMap(125): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-28 16:36:22.077: INFO/Telephony Manager(274): phone state=0
01-28 16:36:22.237: DEBUG/InCallScreen(125): - delayedCleanupAfterDisconnect: phone is idle...
01-28 16:36:22.237: DEBUG/InCallScreen(125): - delayedCleanupAfterDisconnect: finishing InCallScreen...
01-28 16:36:22.257: DEBUG/InCallScreen(125): endInCallScreenSession()...
01-28 16:36:22.268: INFO/ActivityManager(58): moveTaskToBack: 4
01-28 16:36:22.297: DEBUG/InCallScreen(125): setInCallScreenMode: UNDEFINED
01-28 16:36:22.337: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:36:22.337: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = false (isRinging false, isDialing false, showingDisc false)
01-28 16:36:22.357: DEBUG/AudioHardwareInterface(33): setMode(NORMAL)
01-28 16:36:22.397: DEBUG/InCallScreen(125): onPhoneStateChanged()...
01-28 16:36:22.407: DEBUG/InCallScreen(125): updateScreen()...
01-28 16:36:22.417: DEBUG/InCallScreen(125): - updateScreen: updating the in-call UI...
01-28 16:36:22.427: DEBUG/PhoneApp(125): updateWakeState: callscreen true, dialer false, speaker false...
01-28 16:36:22.427: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = false (isRinging false, isDialing false, showingDisc false)
01-28 16:36:22.457: DEBUG/InCallScreen(125): onPause()...
01-28 16:36:22.467: DEBUG/InCallScreen(125): dismissAllDialogs()...
01-28 16:36:22.497: DEBUG/PhoneApp(125): re-enable status bar
01-28 16:36:22.497: DEBUG/PhoneApp(125): StatusBarManager.DISABLE_NONE
01-28 16:36:22.517: DEBUG/PhoneApp(125): updateWakeState: callscreen false, dialer false, speaker false...
01-28 16:36:22.527: DEBUG/PhoneApp(125): updateWakeState: keepScreenOn = false (isRinging false, isDialing false, showingDisc false)
01-28 16:36:22.997: INFO/ActivityManager(58): Start proc android.process.acore for content provider com.android.providers.contacts/.CallLogProvider: pid=295 uid=10000 gids={3003, 1015}
01-28 16:36:23.427: DEBUG/InCallScreen(125): onStop()...
01-28 16:36:23.427: DEBUG/InCallScreen(125): onStop: state = IDLE
01-28 16:36:24.247: INFO/ActivityThread(295): Publishing provider com.android.social: com.android.providers.contacts.SocialProvider
01-28 16:36:24.527: INFO/ActivityThread(295): Publishing provider applications: com.android.providers.applications.ApplicationsProvider
01-28 16:36:25.197: INFO/ActivityThread(295): Publishing provider contacts;com.android.contacts: com.android.providers.contacts.ContactsProvider2
01-28 16:36:27.367: INFO/ActivityThread(295): Publishing provider call_log: com.android.providers.contacts.CallLogProvider
01-28 16:36:27.417: INFO/ActivityThread(295): Publishing provider user_dictionary: com.android.providers.userdictionary.UserDictionaryProvider
01-28 16:36:30.147: INFO/ActivityManager(58): Process com.android.mms (pid 207) has died.
01-28 16:36:30.257: INFO/com.wtts.app.IcyStreamMeta@43f45030(274): {StreamTitle=Pearl Jam~Black~Ten
01-28 16:36:30.257: INFO/com.wtts.app.IcyStreamMeta@43f45030(274): ~334000~S~~~~5:34~Epic}
01-28 16:36:30.257: INFO/com.wtts.app.IcyStreamMeta@43f45030(274): getSongInfo
01-28 16:36:30.277: INFO/com.wtts.app.IcyStreamMeta@43f45030(274): return mData
01-28 16:36:30.707: WARN/AudioFlinger(33): write blocked for 86 msecs, 704 delayed writes, thread 0xb3f0
01-28 16:36:35.727: WARN/AudioFlinger(33): write blocked for 73 msecs, 746 delayed writes, thread 0xb3f0
01-28 16:36:43.327: DEBUG/dalvikvm(274): GC_FOR_MALLOC freed 37781 objects / 927336 bytes in 191ms
01-28 16:36:43.767: INFO/com.wtts.app.IcyStreamMeta@43f123e8(274): {StreamTitle=Pearl Jam~Black~Ten
01-28 16:36:43.767: INFO/com.wtts.app.IcyStreamMeta@43f123e8(274): ~334000~S~~~~5:34~Epic}
01-28 16:36:43.767: INFO/com.wtts.app.IcyStreamMeta@43f123e8(274): getSongInfo

解决方案

You need to manage audio focus to stop music during a phone call.

Check this out: http://developer.android.com/training/managing-audio/audio-focus.html

这篇关于我的流式音频播​​放器继续在通话中发挥 - 不能使它停下来! (安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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