diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-04-23 11:33:41 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-04-23 11:36:04 +0200 |
commit | ceda23935ebd1870eb8a85ec1d78db7bc0875910 (patch) | |
tree | 0e067e3bd4230e1f34292887c2bd224fa54ce540 /src | |
parent | 9a236155dde91494c58ff2be14642bcc1fc38e4b (diff) | |
download | android_packages_apps_Eleven-ceda23935ebd1870eb8a85ec1d78db7bc0875910.tar.gz android_packages_apps_Eleven-ceda23935ebd1870eb8a85ec1d78db7bc0875910.tar.bz2 android_packages_apps_Eleven-ceda23935ebd1870eb8a85ec1d78db7bc0875910.zip |
Add support for playing files and playlists via intent.
Change-Id: I3a4be1d2eec159f47adcd9d7e9dae529ba1dbf35
Diffstat (limited to 'src')
-rw-r--r-- | src/com/andrew/apollo/ui/activities/AudioPlayerActivity.java | 57 | ||||
-rw-r--r-- | src/com/andrew/apollo/utils/MusicUtils.java | 27 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/com/andrew/apollo/ui/activities/AudioPlayerActivity.java b/src/com/andrew/apollo/ui/activities/AudioPlayerActivity.java index fda3ebb..bc6c64e 100644 --- a/src/com/andrew/apollo/ui/activities/AudioPlayerActivity.java +++ b/src/com/andrew/apollo/ui/activities/AudioPlayerActivity.java @@ -25,11 +25,13 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.media.AudioManager; import android.media.audiofx.AudioEffect; +import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; import android.os.Message; import android.os.SystemClock; +import android.provider.MediaStore.Audio.Playlists; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.view.Menu; @@ -198,8 +200,19 @@ public class AudioPlayerActivity extends FragmentActivity implements ServiceConn * {@inheritDoc} */ @Override + public void onNewIntent(Intent intent) { + setIntent(intent); + startPlayback(); + } + + /** + * {@inheritDoc} + */ + @Override public void onServiceConnected(final ComponentName name, final IBinder service) { mService = IApolloService.Stub.asInterface(service); + // Check whether we were asked to start any playback + startPlayback(); // Set the playback drawables updatePlaybackControls(); // Current info @@ -522,6 +535,50 @@ public class AudioPlayerActivity extends FragmentActivity implements ServiceConn } /** + * Checks whether the passed intent contains a playback request, + * and starts playback if that's the case + */ + private void startPlayback() { + Intent intent = getIntent(); + + if (intent == null || mService == null) { + return; + } + + Uri uri = intent.getData(); + String mimeType = intent.getType(); + boolean handled = false; + + if (uri != null && uri.toString().length() > 0) { + MusicUtils.playFile(this, uri); + handled = true; + } else if (Playlists.CONTENT_TYPE.equals(mimeType)) { + long id = intent.getLongExtra("playlistId", -1); + if (id < 0) { + String idString = intent.getStringExtra("playlist"); + if (idString != null) { + try { + id = Long.parseLong(idString); + } catch (NumberFormatException e) { + // ignore + } + } + } + if (id >= 0) { + MusicUtils.playPlaylist(this, id); + handled = true; + } + } + + if (handled) { + // Make sure to process intent only once + setIntent(new Intent()); + // Refresh the queue + ((QueueFragment)mPagerAdapter.getFragment(0)).refreshQueue(); + } + } + + /** * Sets the correct drawable states for the playback controls. */ private void updatePlaybackControls() { diff --git a/src/com/andrew/apollo/utils/MusicUtils.java b/src/com/andrew/apollo/utils/MusicUtils.java index 744f72d..df7e0a0 100644 --- a/src/com/andrew/apollo/utils/MusicUtils.java +++ b/src/com/andrew/apollo/utils/MusicUtils.java @@ -554,6 +554,33 @@ public final class MusicUtils { } /** + * @param context The {@link Context} to use + * @param uri The source of the file + */ + public static void playFile(final Context context, final Uri uri) { + if (uri == null || mService == null) { + return; + } + + // If this is a file:// URI, just use the path directly instead + // of going through the open-from-filedescriptor codepath. + String filename; + String scheme = uri.getScheme(); + if ("file".equals(scheme)) { + filename = uri.getPath(); + } else { + filename = uri.toString(); + } + + try { + mService.stop(); + mService.openFile(filename); + mService.play(); + } catch (final RemoteException ignored) { + } + } + + /** * @param context The {@link Context} to use. * @param list The list of songs to play. * @param position Specify where to start. |