From 8c70f9d05ac86551de20beb62ffefb5c3654584c Mon Sep 17 00:00:00 2001 From: Ravi K Yenduri Date: Fri, 29 May 2009 22:34:25 -0500 Subject: [PATCH] Fix for a hang when attempting to stream a non-existing content. -- StreamStarter Activity is binding the the MediaPlaybackService. As part of this, it is registering for the intent "ASYNC_OPEN_COMPLETE". -- In the normal scenario, after prepareAsync completes, the OnPreparedListener is fired. This ends up broadcasting the "ASYNC_OPEN_COMPLETE" intent. -- Since the StreamStarter Activity has registered for the intent, it will receive the even on it's listener, "onReceive". Here, the MediaPlaybackService "play" is called which starts the actual playback. And, the PLAYBACK_VIEWER intent is sent. This starts the MediaPlaybackActivity. And, "finish" is called in the StreamStarter Activity that will kill the activity. From this point, the MediaPlayback Activity takes over (this activity is the screen where you see the progress bar, and the metadata stuff). -- Now, in this scenario, there is a failure in the "prepareAsync" command. Because of this the ASYNC_OPEN_COMPLETE intent is never broadcasted, and hence the StreamStarterActivity never finishes. - Proposed solution: -- Register the StreamStarter Activity to another intent (PLAYBACK_COMPLETE). -- In OnReceive call, add a condition that when the received intent is PLAYBACK_COMPLETE, "finish" the activity. needs to be broadcasted only if this is a single attempt playback, i.e., if "mOneShot" is "true". --- res/values/strings.xml | 3 +++ src/com/android/music/StreamStarter.java | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/res/values/strings.xml b/res/values/strings.xml index a6f51c6..4d631d8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -279,5 +279,8 @@ Track %d + + + Failed to play the requested stream. diff --git a/src/com/android/music/StreamStarter.java b/src/com/android/music/StreamStarter.java index 0537bad..f7fd5b2 100644 --- a/src/com/android/music/StreamStarter.java +++ b/src/com/android/music/StreamStarter.java @@ -30,6 +30,7 @@ import android.os.IBinder; import android.os.RemoteException; import android.view.Window; import android.widget.TextView; +import android.widget.Toast; public class StreamStarter extends Activity { @@ -57,6 +58,7 @@ public class StreamStarter extends Activity try { IntentFilter f = new IntentFilter(); f.addAction(MediaPlaybackService.ASYNC_OPEN_COMPLETE); + f.addAction(MediaPlaybackService.PLAYBACK_COMPLETE); registerReceiver(mStatusListener, new IntentFilter(f)); MusicUtils.sService.openfileAsync(getIntent().getData().toString()); } catch (RemoteException ex) { @@ -71,6 +73,16 @@ public class StreamStarter extends Activity private BroadcastReceiver mStatusListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(MediaPlaybackService.PLAYBACK_COMPLETE)) { + // You would come here only in case of a failure in the + // MediaPlayerService before PrepareAsync completes + String msg = getString(R.string.fail_to_start_stream); + Toast mt = Toast.makeText(StreamStarter.this, msg, Toast.LENGTH_SHORT); + mt.show(); + finish(); + return; + } try { MusicUtils.sService.play(); intent = new Intent("com.android.music.PLAYBACK_VIEWER"); -- 2.11.0