Another Android question: mp3

Status
Not open for further replies.
I have an mp3 file on my disk. What do I do to get it to play in the default application?

I tried:
Code:
Uri uri = Uri.fromFile(file whose name ends in .mp3);
startActivity(
new Intent(Intent.ACTION_VIEW, uri));

Got an error that there's no such activity.

changed to:
Code:
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("audio/mpeg");
startActivity(intent);
didn't help

Also, I have a tab widget. Is it possible to change the color of the tab labels?
 

Mile Zero

Ars Praetorian
578
Subscriptor++
Try "audio/mp3" for the type. See also this dev group thread: http://groups.google.com/group/android- ... 91d398d37b

The Android Developers group is actually surprisingly handy. You may want to try searching there first, rather than waiting on an answer here.

The TabWidget is, if I remember correctly, implemented using 9-patch skins. If you want to change the color, you'll probably have to pull those out of the SDK and re-color them. If you just want to change the text color, you should be able to do that in a View that you pass in to the TabHost.TabSpec's setIndicator() call.
 

Mile Zero

Ars Praetorian
578
Subscriptor++
I'm not entirely sure why (there's probably a good reason), but I got this to work only if I set it up this way, adding the URI to the Intent after instantiating it:

Code:
        Uri uri = Uri.fromFile(getFileStreamPath("test.mp3"));
        Intent starter = new Intent(Intent.ACTION_VIEW);
        starter.addCategory(Intent.CATEGORY_DEFAULT);
        starter.setDataAndType(uri, "audio/*");
        startActivity(starter);

Otherwise, when I would log the Intent, the URI data wouldn't be attached.
 

Mile Zero

Ars Praetorian
578
Subscriptor++
Tiiba":hu33r4gu said:
ANOTHER question. I have a toggle button. Is there a way to make it so the "light" would be red when it's off, the way it's green when on?

I tried using setButtonDrawable, but it seems like the image is overlaid on the original one and slightly dislocated.

You'll need to clone the button style and invert/replace the images. The relevant files are btn_toggle.xml, btn_toggle_bg.xml, btn_toggle_off.9.png, and btn_toggle_on.9.png in the android-sdk/platforms/*platform dir*/data/res/drawable directory.

Then you replace the ToggleButton's background with your new drawable XML. See also: http://groups.google.com/group/android- ... 22aedbcc13

OR you could use a regular button and set the bottom drawable based on state.
 
Status
Not open for further replies.