Thanks Alex,
Your second suggestion is much like what I ended up doing. This
launches the built in MediaPlaybackActivity and begins playing the
desired track. However, I'm now trying to figure out to keep that
track playing when you back out of the MediaPlaybackActivity. My
problem is that when you back out of the MediaPlaybackActivity, the
track stops. Compare this to launching a track using the built in
MusicBrowser, where the track will continue playing when you back out
of the MediaPlaybackActivity.
Perhaps there's an intent extra required? I tried fiddling with the
boolean "oneshot" intent extra, but that didn't help.
Here is some example code showing how I am querying for and playing
the first track found using the built in MediaPlaybackActivity:
import android.provider.MediaStore.Audio.Media;
// a bunch of other imports...
// query all tracks on sdcard
Cursor cursor = getContentResolver().query(
Media.EXTERNAL_CONTENT_URI, null, null, null, null);
if(cursor == null)
return;
// begin iterating query cursor
if(!cursor.moveToFirst())
return;
// get the id and mime type of the first track in query results
int mediaId = cursor.getInt(
cursor.getColumnIndex(Media._ID));
String mediaMimeType = cursor.getString(
cursor.getColumnIndex(Media.MIME_TYPE));
// form the full URI for the first track
Uri mediaUri = ContentUris.withAppendedId(
Media.EXTERNAL_CONTENT_URI, mediaId);
// form the intent and start the MediaPlaybackActivity
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(mediaUri, mediaMimeType);
startActivity(intent);
On Jan 3, 2:10 am, AlexG <[email protected]> wrote:
> Ok
>
> I found out how to do so:
>
> Intent intent = new Intent();
> intent.setAction(android.content.Intent.ACTION_VIEW);
> File file = new File(<your mp3>);
> intent.setDataAndType(Uri.fromFile(file), "audio/*");
> startActivity(intent);
>
> On Dec 23 2008, 1:16 am,[email protected] wrote:
>
> > Hello,
>
> > From within my application, I'd like to start the standard
> > MusicBrowserActivity (found in Music.apk) which is built into Android.
> > I want to start it programmatically, just as if the user had picked
> > "Music" from the application launcher.
>
> > The class for this Activity is:
> > com.android.music.MusicBrowserActivity
>
> > However, I can't create an Intent explicitly referencing this class
> > because I can't import the package com.android.music (at least not
> > with the default ADT eclipse setup).
>
> > Any ideas on how I can programmatically start MusicBrowserActivity?
>
> > Thanks for any pointers!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---