gapless MediaPlayer...

All your problems with Audio, Video and Images.

gapless MediaPlayer...

Postby medicalfix » Sun Nov 23, 2008 12:46 am

I'm currently trying to play two tracks. Track1 is half of a song and Track2 is the other half of the song...

Now on a gapless player I could play this two files without noticing a blimp or gap in between file plays...

So my research has been trying to find different methods to achieve gapless playback on android, and still trying to find a solution to this problem...

Anyone suggests a solution?
I've tried using one instance of MediaPlayer and also two! lol

Thanks!

Jona
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Top

Postby MrSnowflake » Sun Nov 23, 2008 1:32 pm

Does the problem occur on G1 or emulator or both? Could be an emu slowdown creating this problem.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby medicalfix » Sun Nov 23, 2008 10:36 pm

Hi thanks for your reply,
Yes this problem occurs both in emulation and G1 phone...

I'm running one thread controlling this audio playback. I'm posting a sample here... In this code it seemed to make the playback better by holding the thread on a while loop until media playback was done...

Something to note is that pausing the MediaPlayer is not accurate and not really fast for it to trigger... That is why I don't even bother to pause it here... I just let it finish playback.... So then I het a little over lap on the track and no audio gap on playback...

Hope I make some sence... :P please ask if I don't thanks!


Code:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public void checkMediaPlayerPlay(final String audioFile) throws IllegalArgumentException, IllegalStateException, IOException
  2.  
  3.     {
  4.  
  5.         Runnable updater = new Runnable() {
  6.  
  7.                 public void run() {
  8.  
  9.                         try
  10.  
  11.                         {
  12.  
  13.                                 if(mp1 == null)
  14.  
  15.                                 {
  16.  
  17.                                         mp1 = new MediaPlayer();
  18.  
  19.                                         mp1.setDataSource(audioFile);
  20.  
  21.                                         mp1.prepare();
  22.  
  23.                                         mp1.start();   
  24.  
  25.                                 }
  26.  
  27.                                 else
  28.  
  29.                                 {
  30.  
  31.                                        
  32.  
  33.                                         while((mp1.getDuration()-mp1.getCurrentPosition()) > 400)
  34.  
  35.                                         {
  36.  
  37.                                                
  38.  
  39.                                         }
  40.  
  41.                                         //bufferThrd.sleep(20);
  42.  
  43.                                         //statusLogger("D2: "+mp1.getDuration()+" P1: "+ mp1.getCurrentPosition());
  44.  
  45.                                         //mp1.pause();  //Without pausing works better!
  46.  
  47.  
  48.  
  49.                                         mp1 = new MediaPlayer();
  50.  
  51.                                         mp1.setDataSource(audioFile);
  52.  
  53.                                        
  54.  
  55.                                         //Get Seek Position for next play
  56.  
  57.                                 //      int mp_seekTo = getSeekPosition(duration, position);
  58.  
  59.                                        
  60.  
  61.                                         mp1.prepare();
  62.  
  63.                                 //      mp1.seekTo(mp_seekTo);
  64.  
  65.                                         mp1.start();   
  66.  
  67.                                 }
  68.  
  69.                         } catch (IllegalArgumentException e) {
  70.  
  71.                                         // TODO Auto-generated catch block
  72.  
  73.                                         e.printStackTrace();
  74.  
  75.                                 } catch (IllegalStateException e) {
  76.  
  77.                                         // TODO Auto-generated catch block
  78.  
  79.                                         e.printStackTrace();
  80.  
  81.                                 } catch (IOException e) {
  82.  
  83.                                         // TODO Auto-generated catch block
  84.  
  85.                                         e.printStackTrace();
  86.  
  87.                                 }
  88.  
  89.                 }
  90.  
  91.         };
  92.  
  93.         handler.post(updater);
  94.  
  95.     }
Parsed in 0.039 seconds, using GeSHi 1.0.8.4
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Postby MrSnowflake » Sun Nov 23, 2008 11:12 pm

Well, if pause is slow, I guess the media player needs some more tweaking... I have no idea how to do this thing...
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby medicalfix » Sun Nov 23, 2008 11:21 pm

Mmm... well the whole idea is that I'm building a shoutcast radio streaming player... Currently works like a charm! but playback sounds choppy since MediaPlayer doesn't take a InputStream! lol so I have to play file buffer by file buffer....

Yeah, so anyways I've tried also faking a File but not too sure how you could access a file and write on it at the same time... difficult? lol...
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Postby MrSnowflake » Sun Nov 23, 2008 11:43 pm

Doesn't the mediaplayer suport shoutcast out of the box?
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Postby medicalfix » Sun Nov 23, 2008 11:47 pm

No it doesn't...
There is no player currently for android that would stream internet radio...

Other players that read mp3s from a server and play them to the user... imeem is one of those really! buggy programs that do some weird things... I really don't know what kind of people write this programs... But they aren't good at all... No Software Architecture knowledge? :P
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Postby MrSnowflake » Sun Nov 23, 2008 11:53 pm

You are able to stream music from a server to the MediaPlayer aren't you? If so, you could receive the shoutcast stream to a client and immediately send the audio data from this stream over you own local server, which the MediaPlayer can stream from.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby medicalfix » Mon Nov 24, 2008 12:06 am

[You are able to stream music from a server to the MediaPlayer aren't you?]
-Yes

[If so, you could receive the shoutcast stream to a client and immediately send the audio data from this stream over you own local server, which the MediaPlayer can stream from.]
-If I'm understanding you right this seems like a non distributable solution for the android public? To jump through loops? Sorry maybe I didn't understand you here.... :P

So what I do have,

Well essentially yes I can stream an mp3 file as described on this page:
[http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/]

But streaming an AAC+ stream or MPEG stream is a little different...
and yes I do have this working too...

But a stream of music is hard to make it play... Storing the buffer data in multiple files and read them as needed... it is just way to inefficient! So there is were I'm stuck! Gap-Less Playback of this files so the stream seems natural you could say...
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Postby MrSnowflake » Mon Nov 24, 2008 1:09 am

I mean: create a thread, which has a connection to the shoutcast server. Read the audio stream from shoutcast and buffer it a little, then send the same audio stream again over a self made server in the android application, which streams the shoutcast audio stream again, but now in a format which the MediaPlayer understands. Then make your MediaPlayer tune in on this stream and play from there.

This way, you don't have to use files and you even can make dynamic audio (although this is not what you would use this for).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby medicalfix » Mon Nov 24, 2008 1:17 am

Ok, starting to sound like a good idea! so first is first...

MediaPlayer would read what type of file from this local server? rtsp?

setDataSource(String path)
- Sets the data source (file-path or http/rtsp URL) to use.

setDataSource(FileDescriptor fd, long offset, long length)
- Sets the data source (FileDescriptor) to use.

setDataSource(FileDescriptor fd)
- Sets the data source (FileDescriptor) to use.

setDataSource(Context context, Uri uri)
- Sets the data source as a content Uri.

Thanks for your help man! Really appreciate it!
medicalfix
Junior Developer
Junior Developer
 
Posts: 17
Joined: Sat Nov 01, 2008 9:55 pm

Postby MrSnowflake » Mon Nov 24, 2008 10:59 am

medicalfix wrote:MediaPlayer would read what type of file from this local server? rtsp?
Don't ask me those dirty questions, I'm only here for the idea :). I don't know how you should implement this, I just thought this could help :).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

gapless MediaPlayer...

Postby lym » Mon Dec 22, 2008 2:51 pm

To medicalfix: I think using two files are not a good idea. I've tried it but switching between files just not quick enough.

To MrSnowflake: Your idea is correct, in Android release note (http://code.google.com/intl/zhTW/androi ... NOTES.html)

It mentioned
"Unfortunately, the ability to play audio streams from memory (such as via an InputStream or Reader) will not be possible in Android 1.0. As a workaround, we recommend that developers save media content to SD card and use MediaPlayer to play from a file URI, or embed a small HTTP server and play from a URI on localhost (such as http://127.0.0.1:4242/something)."

I've tried this way, to produce the localhost data stream, I need to assign a predefined size of the media file, otherwise the MediaPlayer prepare will not success. However, when the pre-defined size of media is played completely, MediaPlayer received onCompletioin event and stop playing. I check one open source audio player (Ambient) it use a very large pre-defined size like 100000000, but after playing the internet radio for a long time, eventually the onCompletion event still received, besides the longer the pre-defined size is, the longer you need to wait until MediaPlayer starts playing.

After searching on the internet for a while, I still cannot find a solution until now,do you have any suggestion ?
Thanks for helping.[font=Arial] [/font]
lym
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 22, 2008 2:32 pm

Postby beausejour » Thu Oct 15, 2009 3:10 pm

Anyone found a solution?
beausejour
Junior Developer
Junior Developer
 
Posts: 18
Joined: Tue Apr 15, 2008 4:04 pm
Location: France

Postby Aggiornamento » Wed Nov 18, 2009 9:03 am

to beausejour:

i came out with this problem to, but i already managed to minimalist the gap time between the 2 media player.. when the 1st player is playing, you must call prepare() on the 2nd player ( in other thread ). then seek the currentPossision(), then play the 2nd player.

i know there still a gap between those player, but atleast, it's not that much..

hope this help.
Aggiornamento
Freshman
Freshman
 
Posts: 9
Joined: Wed Nov 18, 2009 8:44 am
Location: Singapore

Top
Next

Return to Multimedia Problems

Who is online

Users browsing this forum: Google [Bot] and 11 guests