×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    61

    2 players method for mediaplayer

    public void play(int index)
    {
    try
    {
    player=Manager.createPlayer(songLocation.elementAt(index).toString());
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    player.start();
    Alert alert=new Alert("Player");
    alert.setString("Player started");
    Display.getDisplay(midlet).setCurrent(alert);
    }
    catch (Exception e) {
    Alert alert=new Alert("Player");
    alert.setString(e.getMessage().toString());
    Display.getDisplay(midlet).setCurrent(alert);
    }

    }

    public void playerUpdate(Player arg0, String arg1, Object arg2) {
    int index=0;
    if(arg1==END_OF_MEDIA)
    {
    index++;
    if(index<songLocation.size())
    play(index);
    }
    }

    }
    hi Righht now iam downlaoding a song and playing in streaming only i used one player .
    as for my client requierement i need to use to 2 player one for downlaoding and other for playing can any one guide for this above code
    Jagadeesh

  2. #2
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    61

    streaming 2 player method how can i apply in this code

    Hi right now iam doing for total song downloading to memory card and it will start playing immediately like that all the chunks so i requiered to to use
    2 players for one is downloading the data and another is playing and //
    how can i use in my code 2 player functionality any one guide this code .
    pls guide me any one for this













    import java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Vector;

    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.Display;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.PlayerListener;
    public class Mp3Download extends Thread implements PlayerListener
    {
    public String url=null;
    InputStream is=null;
    public HttpConnection httpConn=null;
    FileConnection fconn=null;
    FileConnection fconn1=null;
    OutputStream os=null;
    MainMidlet midlet;
    private Player player,player2;
    private String path;
    private Vector songLocation=new Vector();

    public Mp3Download(MainMidlet midlet,String url)
    {
    this.url=url;
    this.midlet=midlet;
    try
    {
    fconn=(FileConnection)Connector.open("file:///C:/j2mestreaming.mp3");
    if(!fconn.exists()){
    fconn.delete();
    fconn.create();
    System.out.println("----------------Creating file..................");
    }
    os=fconn.openOutputStream();
    }
    catch (Exception e) {
    System.out.println("File Connection Error"+e);
    }

    }
    public void run()
    {
    try
    {
    httpConn=(HttpConnection)Connector.open(url);
    httpConn.setRequestMethod(HttpConnection.GET);

    if(httpConn.getResponseCode()==HttpConnection.HTTP_OK)
    {
    System.out.println("content length============================"+httpConn.getLength());
    System.out.println("Http Host============================"+httpConn.getHost());

    is=httpConn.openInputStream();
    byte[] data=new byte[0];
    byte[] buffer=new byte[512];
    int bytesRead;
    int i=0;
    int k=0;
    int index=0;
    while ((bytesRead=is.read(buffer))!=-1) {
    byte[] newdata=new byte[data.length+bytesRead];
    System.arraycopy(data,0,newdata,0,data.length);
    System.arraycopy(buffer,0,newdata,data.length,bytesRead);
    data=newdata;

    if(data.length>1024*512)
    {
    String str=Integer.toString(index);
    String filename="streamingfile_"+str+".mp3";
    String filepath="file:///E:/"+filename;
    songLocation.addElement(filepath);
    path=filepath;
    fconn1=(FileConnection)Connector.open(filepath);
    if(fconn1.exists()){
    fconn1.delete();
    }
    else
    {
    fconn1.create();
    }
    os=fconn1.openOutputStream();
    os.write(data);
    os.close();
    fconn1.close();
    if(index==0)
    {
    play(index);
    }
    index++;
    System.out.println("File No:-"+(k++)+"Created with 512 kb"+data.length/1024);
    data=new byte[0];
    }
    }
    Alert alert=new Alert("Download Page");
    alert.setString("Download Complete");
    Display.getDisplay(midlet).setCurrent(alert);
    }
    }
    catch (Exception e) {
    Alert alert=new Alert("Player");
    alert.setString(e.getMessage().toString());
    Display.getDisplay(midlet).setCurrent(alert);
    }
    }
    public void play(int index)
    {
    try
    {
    player=Manager.createPlayer(songLocation.elementAt(index).toString());
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    player.start();
    Alert alert=new Alert("Player");
    alert.setString("Player started");
    Display.getDisplay(midlet).setCurrent(alert);
    }
    catch (Exception e) {
    Alert alert=new Alert("Player");
    alert.setString(e.getMessage().toString());
    Display.getDisplay(midlet).setCurrent(alert);
    }

    }


    public void playerUpdate(Player arg0, String arg1, Object arg2) {
    int index=0;
    if(arg1==END_OF_MEDIA)
    {
    index++;
    if(index<songLocation.size())
    play(index);
    }
    }

    }
    Jagadeesh

  3. #3
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    61

    2 players method for mediaplayer

    mport java.io.InputStream;
    import java.io.OutputStream;
    import java.util.Vector;
    import javax.microedition.io.Connector;
    import javax.microedition.io.HttpConnection;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.lcdui.Alert;
    import javax.microedition.lcdui.Display;
    import javax.microedition.media.Manager;
    import javax.microedition.media.Player;
    import javax.microedition.media.PlayerListener;
    public class Mp3Download extends Thread implements PlayerListener
    { public String url=null;
    InputStream is=null;
    public HttpConnection httpConn=null;
    FileConnection fconn=null;
    FileConnection fconn1=null;
    OutputStream os=null;
    MainMidlet midlet;
    private Player player,player2;
    private String path;
    private Vector songLocation=new Vector();
    public Mp3Download(MainMidlet midlet,String url)
    { this.url=url;
    this.midlet=midlet;
    }public void run()
    {try{ httpConn=(HttpConnection)Connector.open(url);
    httpConn.setRequestMethod(HttpConnection.GET);
    if(httpConn.getResponseCode()==HttpConnection.HTTP_OK)
    {System.out.println("content length============================"+httpConn.getLength());System.out.println("Http Host============================"+httpConn.getHost());is=httpConn.openInputStream();
    byte[] data=new byte[0];
    byte[] buffer=new byte[512];
    int bytesRead;
    int i=0;
    int k=0;
    int index=0;
    while ((bytesRead=is.read(buffer))!=-1) {
    byte[] newdata=new byte[data.length+bytesRead];
    System.arraycopy(data,0,newdata,0,data.length);
    System.arraycopy(buffer,0,newdata,data.length,bytesRead);
    data=newdata;

    if(data.length>1024*512)
    {
    String str=Integer.toString(index);
    String filename="streamingfile_"+str+".mp3";
    String filepath="file:///E:/"+filename;
    songLocation.addElement(filepath);
    path=filepath;
    fconn1=(FileConnection)Connector.open(filepath);
    if(fconn1.exists()){
    fconn1.delete();
    }
    else
    {
    fconn1.create();
    }
    os=fconn1.openOutputStream();
    os.write(data);
    os.close();
    fconn1.close();
    if(index==0)
    {
    play(index);
    }
    index++;
    System.out.println("File No:-"+(k++)+"Created with 512 kb"+data.length/1024);
    data=new byte[0];
    }
    }
    Alert alert=new Alert("Download Page");
    alert.setString("Download Complete");
    Display.getDisplay(midlet).setCurrent(alert);
    }
    }
    catch (Exception e) {
    Alert alert=new Alert("Player");
    alert.setString(e.getMessage().toString());
    Display.getDisplay(midlet).setCurrent(alert);
    }
    }
    public void play(int index)
    {
    try
    {
    player=Manager.createPlayer(songLocation.elementAt(index).toString());
    player.addPlayerListener(this);
    player.realize();
    player.prefetch();
    player.start();
    Alert alert=new Alert("Player");
    alert.setString("Player started");
    Display.getDisplay(midlet).setCurrent(alert);
    }
    catch (Exception e) {
    Alert alert=new Alert("Player");
    alert.setString(e.getMessage().toString());
    Display.getDisplay(midlet).setCurrent(alert);
    }

    }


    public void playerUpdate(Player arg0, String arg1, Object arg2) {
    int index=0;
    if(arg1==END_OF_MEDIA)
    {
    index++;
    if(index<songLocation.size())
    play(index);
    }
    }
    }
    Hi i have done streaming for only one song right now downloading a song and playing now if ineed to continuely form in my list of songs how can i do can you please tell me how can i go with this.

    Thanks
    Jagadeesh
    Jagadeesh

  4. #4
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,533

    Re: streaming 2 player method how can i apply in this code

    Hi Jagadeesh,

    Please avoid multiposting for same issue. I am merging both your threads as I have done in the past with your threads.

    Edit: found another of your thread with same posting..merging it with this one. Please keep the forum clean and dont post continously as you have been repeatidly doing.

    Thanks!

Similar Threads

  1. qmediaplayer no service found for - "com.nokia.qt.mediaplayer"
    By oruccim in forum [Archived] Qt Mobility Project
    Replies: 7
    Last Post: 2012-07-06, 08:46
  2. Does multiple players work for 60 and 40 ? (2 wavs + 1 midi at the same time)
    By loup in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2010-06-15, 19:24
  3. Pool of Players for streaming???
    By IkerJ in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2007-06-21, 12:07
  4. Maximum players for a game
    By gaya3sr in forum Mobile Java Games
    Replies: 1
    Last Post: 2007-04-26, 20:03

Posting Permissions

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