Tutorial: Custom Media Streaming for Android's MediaPlayer

Tutorials with advanced 'difficulty' and more Lines of Code.

Postby marielisacr » Fri May 23, 2008 3:29 am

Hi,

i check what you said, the method deleteTrackName() is also called when i debug your tutorial, the same for enable() and disable() so i guess it isn't the problem. I don't kwon what they do, i only found people with my same problem but with any solution post it.

If you said that you did a robust media player i guess it can be done but i really don't have any idea what is happening now, if you figure out anything please tell me, i really need it.

Thanks for your help
marielisacr
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed May 21, 2008 10:04 pm

Top

Postby biosopher » Fri May 23, 2008 3:41 am

To debug further, you need to put in more debug traces to figure out exactly which method is being called and failing.

Sadly that's the only way to develop the robust player I now have. It took quite awhile to debug and I had many similar application crashes along the way.

If you're using Eclipse, it would be much easier to skip the debug traces and set breakpoints.

Once you've done that & figured out which method call creates the crash, let me know. I can help you track it down more from there.

Biosopher
biosopher
Developer
Developer
 
Posts: 26
Joined: Sat Mar 15, 2008 8:14 pm
Location: San Francisco, California

Postby marielisacr » Fri May 23, 2008 4:19 am

Thanks, i will do that.

I will continue debbuging the aplication, as sun as i figure out which method is crashing i will let you know.

Thanks for your help
marielisacr
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed May 21, 2008 10:04 pm

Postby marielisacr » Fri May 30, 2008 11:19 pm

Hi biosopher,

I solve my problem, i was working in other things when i realize wath was the problem.

To start i did a better management of the files, and the main problem was to many instances of the MediaPlayer, instead of use new MediaPlayer y just used the method reset().

Thank for everything and good luck in the android challenge ;)
marielisacr
Junior Developer
Junior Developer
 
Posts: 13
Joined: Wed May 21, 2008 10:04 pm

Postby exospy » Mon Jun 08, 2009 4:27 am

Hey - this is great work. I am anxious to get it working. I downloaded the .zip and imported the files as a project into Eclipse (i had to put the files into a directory outside of my workspace because I was getting a project description error when i tried to add existing android project).

So i am not sure if that is why I am receiving the error below. I ensured that it is on Android 1.5.

Error:
[2009-06-07 21:38:13 - Tutorials] WARNING: Application does not specify an API level requirement!
[2009-06-07 21:38:13 - Tutorials] Device API version is 3 (Android 1.5)

[2009-06-07 21:38:13 - Tutorials] Uploading Tutorials.apk onto device 'emulator-5554'
[2009-06-07 21:38:13 - Tutorials] Installing Tutorials.apk...
[2009-06-07 21:38:16 - Tutorials] Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
[2009-06-07 21:38:16 - Tutorials] Please check logcat output for more details.
[2009-06-07 21:38:16 - Tutorials] Launch canceled!


anyone else experienced this?

Any help much appreciated. I am seeking to try and eventually get this working with Shoutcast....
exospy
Freshman
Freshman
 
Posts: 4
Joined: Mon Jun 08, 2009 3:40 am
Location: San Francisco

WAV file not working while streaming

Postby nishantshah » Tue Sep 08, 2009 3:56 am

Hi,

I am working on Android's Media Player.
I have developed simple code in Android using Media Player that works for wav and mp3 files.

MediaPlayer mp = MediaPlayer.create(this, R.raw.chimes);
mp.start();

I have also developed simple audio java code using built in package of Java (javax.sound.sampled). The audio files contains stream data(FileOutputStream).
But Android does not support sound package.

Is there any other way to play wav file in Android while streaming?

Thanks in advance
Reply With Quote
nishantshah
Once Poster
Once Poster
 
Posts: 1
Joined: Tue Sep 08, 2009 3:49 am

Top

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby pradeep_android » Thu Mar 18, 2010 12:27 pm

biosopher wrote:I have had absolutely no luck streaming audio using the built-in MediaPlayer functionality so I decided to write my own streaming utility for the MediaPlayer.

My solution is now documented as a tutorial on my blog including including source code:

blog.pocketjourney.com.

Here's a sneak peak at a few screenshots:

Image

Please check it out & leave a comment on my blog if you have questions.

Best of luck,
biosopher




Great player.
I tried adding seek bar instead of progress bar.
But had a problem with seeking the song to exact location of bar.
plz help me with this.
pradeep_android
Freshman
Freshman
 
Posts: 7
Joined: Thu Feb 04, 2010 5:19 am

Postby jonneymendoza » Thu May 13, 2010 5:22 pm

been reading the OP's code and it looks good but im a bit confused at one thing.

u store a buffer of the music and replace the old buffered file with the newly downloaded one?

doesnt this provide a gap between the song your streaming as you have to set the mediaPlayer with the newly buffered music file?

You say that it is impossible to add content to the file that the mediaPlayer is playing at the moment but what is wrong with simply doing this:

mediaPlayer.create(context, Uri.parse("http://media/music/micheal_Jackson.mp3") )
mediaPlayer.start();
jonneymendoza
Developer
Developer
 
Posts: 36
Joined: Fri Sep 04, 2009 10:30 am

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby tiger79 » Fri May 28, 2010 10:51 am

nothing wrong with that if you have the complete file on your device...
He is trying to solve the streaming problem from a server, as in the file is not on your device..
So because MediaPlayer used not to be able to stream it would first download the whole file and then play it, so it could take a whole lotta time before the playing actually started...
Nowadays MediaPlayers streams MP3's from web-servers, even though it's very very very picky about the format...
Just have a look when this Thread was started, and with which Android Version ;)
tiger79
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 14, 2010 5:30 pm

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby jonneymendoza » Fri May 28, 2010 10:58 am

tiger79 wrote:nothing wrong with that if you have the complete file on your device...
He is trying to solve the streaming problem from a server, as in the file is not on your device..
So because MediaPlayer used not to be able to stream it would first download the whole file and then play it, so it could take a whole lotta time before the playing actually started...
Nowadays MediaPlayers streams MP3's from web-servers, even though it's very very very picky about the format...
Just have a look when this Thread was started, and with which Android Version ;)
jonneymendoza
Developer
Developer
 
Posts: 36
Joined: Fri Sep 04, 2009 10:30 am

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby jonneymendoza » Fri May 28, 2010 11:14 am

Again, there should be a gap between when you grab teh newly buffered track, create a new mediaPlayer and start playing that track.

Also, is it certain that an incomplete track can be played on MediaPlayer? doesnt the .mp3 have to be fully downloaded in order to play it? Also, it seems its possible to play a .DAT file?
jonneymendoza
Developer
Developer
 
Posts: 36
Joined: Fri Sep 04, 2009 10:30 am

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby tiger79 » Fri May 28, 2010 11:33 am

yup,
there is a gap... thats mostly because the second mediaplayer is started when the first one actually finishes... Making a new mediaplayer inbetween, like you are mentioning, would even create a bigger gap, thats also why in his newer versions of the code the mediaplayers get created, and prepared right away, then stored in a Vector and get loaded from there when the playing mediaplyer gets to its end... Having an already filled and prepared MediapPlayer ready to use is obviously faster...

Also, is it certain that an incomplete track can be played on MediaPlayer? doesnt the .mp3 have to be fully downloaded in order to play it?

I have been stremaing from mp3 servers with Android 1.6 MediaPlayer so yes it's certain for me... Just, as I previously mentioned, the MediaPlayer is picky about mp3 streams... Shoutcast for example wont play even if it's mp3...
This automatically answers your second question as well...
tiger79
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 14, 2010 5:30 pm

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby jonneymendoza » Fri May 28, 2010 11:50 am

im guessing a .DAT file can be played even when its incomplete but a .mp3 file cant? the tutorials uses a .DAT file to play the media file
jonneymendoza
Developer
Developer
 
Posts: 36
Joined: Fri Sep 04, 2009 10:30 am

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby tiger79 » Fri May 28, 2010 1:27 pm

actually, if you read the complete tutorial, he is downing an MP3 file, and saving it as chunks into .dat files...
Still the headers inside the .dat file will still hint to an mp3 file thats why the MediaPlayer can play it... Or do you know of any codec which creates .dat files ?
So you will make an "infinite" stream into a finite file, which can be played right away by the MediaPlayer because it's a complete file...
and yes a .dat file can be played because it's always complete ;)
tiger79
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Jan 14, 2010 5:30 pm

Re: Tutorial: Custom Media Streaming for Android's MediaPlay

Postby praveenb » Sat May 29, 2010 12:08 am

Hi Biosopher,
I worked with your Streaming media player. It worked very well for me. Im using this for playing audio stream from radio station url where streaming may be continuous. I increased buffer size to 10Mb in moveFile(oldFileLoc,newFileLoc) method to play continuously. Here sd caching is happening which could result in crash if user has insufficient memory.

SO is there any another method or player service which works without SD caching.

Pls let me know the better way to come out of this issue..

Thanks.
praveenb
Freshman
Freshman
 
Posts: 9
Joined: Thu May 27, 2010 7:10 pm

Top
PreviousNext

Return to Advanced Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests