how to download and play mp3 files?

All your problems with Audio, Video and Images.

how to download and play mp3 files?

Postby jjoe64 » Wed Dec 30, 2009 4:32 pm

Hello.

Do anybody know how I can download and play a mp3 file with the MediaPlayer-Class?

That's my Java Code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 // Local File output
  2.                 FileOutputStream file_out = context.openFileOutput("tmp_test.mp3", Context.MODE_WORLD_READABLE);
  3.                
  4.                 // Download
  5.                 URL link = new URL("http://192.168.178.9/das.mp3");
  6.                 URLConnection yc = link.openConnection();
  7.                 BufferedReader in = new BufferedReader(
  8.                                         new InputStreamReader(
  9.                                         yc.getInputStream()));
  10.                 // Write data to file
  11.                 int _byte;
  12.                 while ((_byte = in.read()) != -1)
  13.                 {
  14.                         file_out.write(_byte);
  15.                 }
  16.                
  17.                 in.close();
  18.                 file_out.close();
  19.  
  20.                 // 3. play mp3
  21.                 MediaPlayer mp = new MediaPlayer();
  22.                 mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
  23.                 mp.setDataSource("tmp_test.mp3");
  24.                 mp.prepare();
  25.                 mp.start();
  26.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


I tried this, but there comes an Error :
PlayerDriver - Command PLAYER_SET_DATA_SOURCE completed with an error or info PVMFErrNotSupported
MediaPlayer - error (1, -4)


The mp3 file must be okay, because when I put the file in the resource-folder I can play it simple:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         MediaPlayer mp = MediaPlayer.create(context, R.raw.das);
  2.         mp.start();
  3.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Notice, that I cannot open the URL to mp3 directly, because later I want to change some bytes in the mp3 file.

Thanks.
jjoe64
Freshman
Freshman
 
Posts: 4
Joined: Tue Dec 29, 2009 6:04 pm

Top

Re: how to download and play mp3 files?

Postby klonk » Wed Jun 15, 2011 1:16 pm

Having the same problem! Maybe someone can help?
klonk
Developer
Developer
 
Posts: 37
Joined: Fri May 06, 2011 4:41 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 13 guests