×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    26

    Mp3 Streaming Using Player Switching

    Hi all,

    I am developing a sample application which can play shoutcast mp3 streams (Developing for S40 platforms, CLDC 1.1, MIDP 2.0). I am using two player switching for continues play back.

    I used the below logic for streaming.
    1. Buffer enough chunks
    2. Start Player1
    3. Wait Player1 to finish
    4. Start Player2
    5. Wait Player2 to finish
    6. repeat... 2



    The problem is, listener can feel 1 Second silence(Gap) while switching between players.
    I would like to know is it possible to stream audio from server without gaps (while switching the players)?



    Thanks in advance
    Anish

  2. #2
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: Mp3 Streaming Using Player Switching

    Hi anishk,

    you can do with one player using midlet.platformRequest(url) call.
    see the example Episode 4: Progressive Audio here

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    26

    Re: Mp3 Streaming Using Player Switching

    Thanks bandarap,

    But it doesn't work for me. Did you checked http://www.shoutcast.com an online radio website.
    There we can download playlist file which contains URL of stream like this

    [playlist]
    numberofentries=1
    File1=http://91.121.92.167:4610
    Title1=Bollywood Radio
    Length1=-1
    Version=2

    If I give this URL (http://91.121.92.167:4610) to Manager.createPlayer(url) throws MediaException invalid locator.
    If I give this URL (http://91.121.92.167:4610) to midlet.platformRequest(url) starts downloading stream endless.

    Any other way to stream this kind of media.

    Thanks and Regards
    Anish

  4. #4
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: Mp3 Streaming Using Player Switching

    Hi Anishk,

    the URL you are testing "http://91.121.92.167:4610" is not working. you can check this by pasting in address bar of the browser and also compare with my previous reply example url. Example url plays audio when pasted in browser address bar.

    Also make sure that "progressive_download: enabled" is added in the JAD file.

    Exception clearly says that "MediaException - Thrown if a Player cannot be created for the given locator."

  5. #5
    Registered User
    Join Date
    Mar 2009
    Posts
    26

    Re: Mp3 Streaming Using Player Switching

    Thanks bandarap,

    The url will not work in browser since it is stream url.
    Lets check the following J2SE code for downloading mp3 chunks from the URL "http://91.121.92.167:4610".

    HTML Code:
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;
    
    public class TestMp3Download {
    
    	public static void main(String[] args) {
    		try {
    			System.out.println("Opening connection");
    			URL url = new URL("http://91.121.92.167:4610");
    			HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
    			System.out.println("Connection opened");
    			InputStream is = httpURLConnection.getInputStream();
    
    			byte[] readBytes = new byte[1024];
    			int lengthRead = -1;
    
    			int chunkSize = 98304;
    			String fileName = "myfile-";
    			int fileCount = 1;
    			File file = new File(fileName + fileCount++ + ".mp3");
    			FileOutputStream fio = new FileOutputStream(file);
    			int totalRead = 0;
    			while ((lengthRead = is.read(readBytes)) != -1) {
    				System.out.println("length read " + lengthRead);
    				totalRead += lengthRead;
    				fio.write(readBytes, 0, lengthRead);
    				if(totalRead > chunkSize){
    					totalRead = 0;
    					//open next file
    					try {
    						fio.close();
    					} catch (Exception e) {
    					}	
    					fio = null;
    					fio = new FileOutputStream(new File(fileName + fileCount++ + ".mp3"));
    				}
    			}
    		} catch (IOException e) {
    		}
    	}
    }
    You can play the downloaded chunks (.mp3 file) using mediaplayer.

    I need to stream from above kind of URL, The URL in the example source just points to an mp3 file (Known length) uploaded to the server.

    Thanks and Regards
    Anish

  6. #6
    Nokia Developer Expert
    Join Date
    May 2012
    Location
    Espoo
    Posts
    224

    Re: Mp3 Streaming Using Player Switching

    Hi Anishk,

    Seems your url supports server streaming not http stream or progressive stream.
    You can read difference between server streaming and http streaming here

    Nokia S40 devices by default support only progressive streaming (http streaming). Pass progressive streaming url to midlet.platformRequest(url) API that downloads music file to file system (for example to memory card or mass memory in the device) and at the same time plays the music with platform music player. Tested this with Asha 303 and works fine.

    If you want to support server streaming, your approach as explained in the first post is one of the choice.
    And comes to your question "listener can feel 1 Second silence (Gap) while switching between players".
    To avoid one second gap while switching players, do the following trick as explained in this thread
    Get the duration of the buffer or chunk that you are going to play, start it --start a new thread pre-fetch the next chunk and wait (sleep) for the duration left for the first player - 500ms and launch the next player.
    No need to check the timeplayed, try with Player.getDuration() and put in some logic to take care of the time, next prefech and start of the next player.
    Last edited by bandarap; 2012-06-19 at 13:10.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    26

    Re: Mp3 Streaming Using Player Switching

    Thanks bandarap,
    I will check it.

    Thanks and Regards
    Anish

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Mp3 Streaming Using Player Switching

    I have tested this a couple of years ago and I had the exact same issues... Unfortunately I didnt find a solution to it, it takes some time for the second player (even if it's in prepared state) to actually start up...
    In the end I had inbetween 200 to 300ms between the two players (on a N95 and N96 back then), which obviously is audible thus not a working solution... I managed to get a somewhat better solution by copying some of the last data of chunk 1 into the beginning of chunk 2, and then overlap those by starting the second player exactly the same amount of overlapped time before the first player ended... The problem was that this amount of time actually changed (like I said, between 200ms to 300ms), which results in sometimes a little piece of music being played twice... So those were my options : the gap, or sometimes hearing a little piece of music playing twice... Experience among users actually preferred the second option, which obviously can be minimzed by taking somewhat bigger chunks of data to be played...
    Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them.

Similar Threads

  1. Media player streaming
    By pfci in forum Streaming and Video
    Replies: 1
    Last Post: 2009-04-28, 19:18
  2. real player or nokia player in 6600 support 3gpp streaming?
    By diabol in forum Streaming and Video
    Replies: 4
    Last Post: 2008-05-25, 14:39
  3. AMR audio streaming player
    By antix in forum Mobile Java Media (Graphics & Sounds)
    Replies: 5
    Last Post: 2007-03-13, 01:12
  4. MP3 Streaming like real player...
    By senthilkumar05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2006-11-17, 08:21
  5. A Player for streaming
    By Paranoid_Android in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-07-17, 12:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×