×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    how to play two or more audio files in J2me

    i m developing a J2me S60 app, which can play multiple audio files.i tried this code but problem is ,it takes delay after playing one file i.e to start the next one. can anyone tell me how to play these files (one after another) using MMAPI.

    public class AudioPlayer implements javax.microedition.media.PlayerListener{

    Player player;
    int count=0;

    public void playMedia(){

    try{

    player = Manager.createPlayer(getClass().getResourceAsStream(audioFiles[count]),"audio/x-amr");
    player.addPlayerListener(this);
    player.start();

    }
    catch (Exception e) {
    return ;
    }
    }


    public void playerUpdate(Player p,String event,Object eventData) {

    if (event==PlayerListener.END_OF_MEDIA)
    {
    try{
    if(++count == audioFiles.length)
    p.stop();
    else {
    player = Manager.createPlayer(getClass().getResourceAsStream(audioFiles[count]]),"audio/x-amr" );
    player.addPlayerListener(this);
    player.start();
    }
    }
    catch (Exception e) {
    return;
    }
    }
    }

    }

    also i was thinking about another option to reduce the delay, that is to merge the N number of files and create a new one...but i havn't tried this bcz didnt get any clue on how to merge files....any anyone has experienced this...plz help...its realy urgent

    Thanx

  2. #2
    Nokia Developer Expert
    Join Date
    Aug 2007
    Posts
    1,595
    [URL="http://library.forum.nokia.com/java"][B] >>> Java Developer's Library <<<[/B][/URL]
    [URL="https://www.developer.nokia.com/Resources/Support/Technical_support.xhtml"] [B]>>> Technical Support for Java ME development <<<[/B][/URL]
    [URL="https://publish.ovi.com/info/"][B]>>> Nokia Publish: reach millions of Nokia users worldwide through Nokia Store <<<[/B][/URL]

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    Re: how to play two or more audio files in J2me

    how about this aproach ...it has reduced the delay.


    public class AudioPlayer implements javax.microedition.media.PlayerListener{


    private Player player;

    public playMedia(String[] audiofile){

    int adflen = audiofile.length;

    InputStream is;

    try{

    byte[][] bfiles = new byte[adflen][];
    byte[] temp = new byte[800];// all files in audiofile are approx of 800bytes
    int totalbytes = 0; int numread = 0; int strmlen = 0;

    for(int k=0; k<adflen; k++)
    {
    numread =0; totalbytes = 0;

    is = this.getClass().getResourceAsStream(audiofile[k]);

    while(numread >= 0)
    {
    totalbytes+=numread;
    numread = is.read(temp);
    }

    bfiles[k] = new byte[totalbytes];
    strmlen+=totalbytes;
    is.close();

    for(int cnt=0; cnt<totalbytes; cnt++)
    bfiles[k][cnt] = temp[cnt];
    }


    byte[] stream = new byte[strmlen];
    int pos =0;

    for(int out=0; out<adflen; out++)
    for(int in=0; in<bfiles[out].length; in++)
    stream[pos++] = bfiles[out][in];

    ByteArrayInputStream bais = new ByteArrayInputStream( stream );

    player = Manager.createPlayer(bais,"audio/x-amr");
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    player.start();
    }

    catch (Exception e) {
    System.out.println(e.toString());
    }
    }


    public void playerUpdate(Player p,String event,Object eventData) {

    if (event == PlayerListener.END_OF_MEDIA)
    {
    try {
    p.deallocate();
    p.close();
    }
    catch(Exception e){
    p.deallocate();
    p.close();
    return;
    }

    }
    }
    need advice!
    Thanx

Similar Threads

  1. how to play multiple audio files in j2me
    By A.Saleh in forum Audio
    Replies: 2
    Last Post: 2010-06-08, 22:48
  2. Play audio files
    By pankaj gupta55 in forum Symbian
    Replies: 17
    Last Post: 2010-04-26, 09:30
  3. Cannot play more than 3 audio files?
    By hyon in forum Symbian
    Replies: 3
    Last Post: 2008-02-18, 05:19
  4. play audio files
    By khalandar in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2007-03-07, 05:58
  5. How to play two audio files at the same time?
    By ash_bhatia in forum Symbian Media (Closed)
    Replies: 1
    Last Post: 2005-12-20, 02:42

Posting Permissions

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