9

On the stock Droid and Nexus One, an intent like this:

new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.parse("http://example.com/somemp3.mp3"), "audio/mp3");

works just fine and pops open the system music player to stream the file. But it doesn't match any activities on the HTC Incredible, causing a force-close when I call startActivity on it (I'm guessing due to missing intent filters in SenseUI's replacement applications). I'd prefer not to have to manage a MediaPlayer instance myself if I don't have to; does anyone know if there's a way to structure an Intent to convince the Incredible to play an MP3 stream over HTTP in its built-in Music or Streaming Media apps?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Yoni Samlan
  • 37,905
  • 5
  • 60
  • 62
  • For what it's worth I wound up giving up and implementing a MediaPlayer-based activity to play the MP3s in app. I still think there ought to be a more elegant and simpler solution with Intents, though. – Yoni Samlan Jul 22 '10 at 01:06

4 Answers4

1

Try "audio/*" type. I think it works.

Fedor
  • 43,261
  • 10
  • 79
  • 89
1

This code worked for me:

Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse(url), "audio/*");
context.startActivity(i);

You can also view video streaming, using "video/*" type.

This method worked on both Android 1.5 and 2.2, not sure about SenseUI compatibility. "audio/mp3" didn't work for me either, so it's not senseUI specific.

NoBugs
  • 9,310
  • 13
  • 80
  • 146
  • That was Fedor's answer... I still have to test it out on a SenseUI phone (which was the real sticking point -- for non-sense devices, "audio/mp3" worked fine anyways). – Yoni Samlan Jun 30 '11 at 15:55
  • Funny, I thought using android.content.Intent.ACTION_VIEW instead of Intent.ACTION_VIEW made a difference, but it seems it works the same now. Did you try "(star)/(star)" for type? – NoBugs Jun 30 '11 at 16:23
0

to play audio file from server try this

try {
    MediaPlayer player = new MediaPlayer();
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);
    player.setDataSource("http://xty/MRESC/images/test/xy.mp3"
        );
    player.prepare();
    player.start();

} catch (Exception e) {
// TODO: handle exception
}

also in your manifest file use this permission..

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

hope help you

this code piece originally from here

Community
  • 1
  • 1
Deepak Swami
  • 3,838
  • 1
  • 31
  • 46
0

I was dealing with a similar problem, and when i was into search, i've found this link which helps you do some streaming from a mp3 source.

Hope it helps.

Enrique Diaz
  • 573
  • 4
  • 13
  • That's helpful if you're rolling your own MediaPlayer based solution to playing from a file on disk, but doesn't really answer the original question (how to open an HTTP MP3 URI in the system music player in SenseUI so you don't *have* to deal with all that MediaPlayer nonsense). – Yoni Samlan Feb 23 '11 at 15:39