开发者

My streaming audio player continues to play during a phone call - cannot make it stop! (Android)

开发者 https://www.devze.com 2023-02-07 21:37 出处:网络
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 an

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 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.

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: callsc开发者_如何学JAVAreen 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


if (player != null) {
   player.stop();
   player= null;    
  }


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号