Update image of play/pause button when audio playback starts
[pub/Android/ownCloud.git] / src / com / owncloud / android / media / MediaService.java
index a511852..f8e70fe 100644 (file)
@@ -62,7 +62,8 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     private static final String MY_PACKAGE = MediaService.class.getPackage() != null ? MediaService.class.getPackage().getName() : "com.owncloud.android.media";
     
     /// Intent actions that we are prepared to handle
-    public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".android.media.action.PLAY_FILE";
+    public static final String ACTION_PLAY_FILE = MY_PACKAGE + ".action.PLAY_FILE";
+    public static final String ACTION_STOP_ALL = MY_PACKAGE + ".action.STOP_ALL";
 
     /// Keys to add extras to the action
     public static final String EXTRA_FILE = MY_PACKAGE + ".extra.FILE";
@@ -72,7 +73,10 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     public static final int OC_MEDIA_ERROR = 0;
 
     /** Time To keep the control panel visible when the user does not use it */
-    public static final int MEDIA_CONTROL_LIFE = 5000;
+    public static final int MEDIA_CONTROL_SHORT_LIFE = 5000;
+    
+    /** Time To keep the control panel visible when the user does not use it */
+    public static final int MEDIA_CONTROL_PERMANENT = 0;
     
     /** Volume to set when audio focus is lost and ducking is allowed */
     private static final float DUCK_VOLUME = 0.1f;
@@ -129,7 +133,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     private IBinder mBinder;
 
     /** Control panel shown to the user to control the playback, to register through binding */
-    private MediaController mMediaController;
+    private MediaControlView mMediaController;
     
 
     
@@ -228,6 +232,9 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
         String action = intent.getAction();
         if (action.equals(ACTION_PLAY_FILE)) { 
             processPlayFileRequest(intent);
+            
+        } else if (action.equals(ACTION_STOP_ALL)) {
+            processStopRequest(true);
         }
 
         return START_NOT_STICKY; // don't want it to restart in case it's killed.
@@ -426,10 +433,13 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
             createMediaPlayerIfNeeded();
             mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
             String url = mFile.getStoragePath();
+            /* Streaming is not possible right now
             if (url == null || url.length() <= 0) {
                 url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath();
             }
             mIsStreaming = url.startsWith("http:") || url.startsWith("https:");
+            */
+            mIsStreaming = false;
             
             mPlayer.setDataSource(url);
 
@@ -471,9 +481,6 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     
     /** Called when media player is done playing current song. */
     public void onCompletion(MediaPlayer player) {
-        if (mMediaController != null) {
-            mMediaController.hide();
-        }
         Toast.makeText(this, String.format(getString(R.string.media_event_done, mFile.getFileName())), Toast.LENGTH_LONG).show();
         processStopRequest(true);
         return;
@@ -493,7 +500,7 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
         }
         configAndStartMediaPlayer();
         if (mMediaController != null) {
-            mMediaController.show(MEDIA_CONTROL_LIFE);
+            mMediaController.updatePausePlay();
         }
     }
     
@@ -566,10 +573,6 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     public boolean onError(MediaPlayer mp, int what, int extra) {
         Log.e(TAG, "Error in audio playback, what = " + what + ", extra = " + extra);
         
-        if (mMediaController != null) {
-            mMediaController.hide();
-        }
-
         String message = getMessageForMediaError(this, what, extra);
         Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
         
@@ -670,15 +673,11 @@ public class MediaService extends Service implements OnCompletionListener, OnPre
     }
 
 
-    protected void setMediaContoller(MediaController mediaController) {
-        if (mMediaController != null) {
-            mMediaController.hide();
-        }
+    protected void setMediaContoller(MediaControlView mediaController) {
         mMediaController = mediaController;
-        
     }
 
-    protected MediaController getMediaController() {
+    protected MediaControlView getMediaController() {
         return mMediaController;
     }