OSDN Git Service

Fix for a hang when attempting to stream a non-existing content.
authorRavi K Yenduri <yenduri@pv.com>
Sat, 30 May 2009 03:34:25 +0000 (22:34 -0500)
committerMarco Nelissen <marcone@google.com>
Thu, 4 Jun 2009 17:48:17 +0000 (10:48 -0700)
 -- 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
src/com/android/music/StreamStarter.java

index a6f51c6..4d631d8 100644 (file)
 
     <!-- Title for track number in music gadget -->
     <string name="gadget_track">Track <xliff:g id="track_number">%d</xliff:g></string>
+
+    <!-- Toast after streamStarter activity receives PLAYBACK_COMPLETE in case of an error -->
+    <string name="fail_to_start_stream">Failed to play the requested stream.</string>
 </resources>
 
index dc18c41..a43dbf5 100644 (file)
@@ -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");