×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Thumbs up Problem with using DataSource

    Hi friends,

    I want to develop a player application using DataSource class.

    I have written a sample code for implementing the DataSource concept.

    public class SecDataSource extends DataSource
    {


    private String locator;


    private SecSourceStream[] streams;


    private boolean connected = false;

    public SecDataSource(String locator)
    {
    super(locator);
    setLocator(locator);
    }

    public void setLocator(String locator)
    {
    this.locator = locator;

    }

    public String getLocator() {

    return locator;
    }

    public void connect() throws IOException
    {


    if (connected) return;


    if (locator == null)
    throw new IOException("locator is null");


    streams = new SecSourceStream[1];


    streams[0] = new SecSourceStream(locator);


    connected = true;

    }

    public void disconnect()
    {


    if (streams != null)
    {


    try
    {
    ((SecSourceStream)streams[0]).close();
    }
    catch (IOException ioex) { } // silent
    }


    connected = false;
    }

    public void start() throws IOException
    {

    if (!connected) return;



    ((SecSourceStream)streams[0]).start();

    }

    public void stop() throws IOException
    {
    if (!connected) return;


    ((SecSourceStream)streams[0]).close();

    }

    public String getContentType()
    {

    return "video/3gpp";
    }

    public Control[] getControls()
    {

    return new Control[0];
    }

    public Control getControl(String controlType)
    {

    return null;
    }

    public SourceStream[] getStreams()
    {

    return streams;
    }
    }


    public class SecSourceStream implements SourceStream
    {

    private InputStream is;
    int m_CurLoc;
    FileConnection fc;
    private DatagramConnection socket;

    public SecSourceStream(String address) throws IOException
    {


    try
    {
    fc = (FileConnection)Connector.open(address);
    }
    catch(Exception e)
    {


    }



    }

    public void start() throws IOException
    {



    try
    {
    is = fc.openInputStream();


    }
    catch(Exception e)
    {
    System.out.println("Exception in sourcestream start():"+e);
    }


    }

    public void close() throws IOException
    {

    try
    {
    is.close();
    fc.close();
    }
    catch(Exception e)
    {

    }
    }

    public int read(byte[] buffer, int offset, int length)
    throws IOException
    {



    byte[] Player_Sec_KeyCode = new byte[length];
    is.read(Player_Sec_KeyCode);

    return buffer.length;
    }



    public long seek(long where) throws IOException
    {

    throw new IOException("cannot seek");
    }

    public long tell()
    {

    return -1;
    }

    public int getSeekType()
    {
    return NOT_SEEKABLE;
    }

    public Control[] getControls()
    {

    return null;
    }

    public Control getControl(String controlType)
    {
    return null;
    }

    public long getContentLength()
    {

    return -1;
    }

    public int getTransferSize()
    {

    return -1;
    }

    public ContentDescriptor getContentDescriptor()
    {
    return new ContentDescriptor("video/3gpp");

    }
    }

    and in player code:
    try
    {
    Player p = Manager.createPlayer(new SecDataSource("file:///C:/Data/Sounds/<some_fileName>.3gp));

    p.realize();
    p.prefetch();
    p.start();
    System.out.println("Player started");
    }
    catch(Exception e)
    {
    System.out.println("Exception :"+e);
    }

    This code is not working in my S60 emulator.

    Please help me.

    Thanks,
    Manoj.

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,192

    Re: Problem with using DataSource

    Would you mind sharing what "is not working" means?
    Do you get an exception? Unexpected behavior? What?

    Hartti

  3. #3
    Regular Contributor
    Join Date
    Jan 2008
    Posts
    272

    Re: Problem with using DataSource

    Quote Originally Posted by hartti View Post
    Would you mind sharing what "is not working" means?
    Do you get an exception? Unexpected behavior? What?

    Hartti
    The player is unable to play the specified file and giving exception as "javax.microedition.media.MediaException: unable to parse the protocol".

    But when I created the player:
    p = Manager.createPlayer("file:///C:/Data/Sounds/<some_fileName>.3gp");

    the above code works.

    Please help me to use DataSource.

    Thanks,
    Manoj.

  4. #4
    Nokia Developer Expert
    Join Date
    Jun 2005
    Posts
    923

    Re: Problem with using DataSource

    Why do you need a DataSource at all? You are trying to re-implement something which is already done.

  5. #5
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    51

    Re: Problem with using DataSource

    Quote Originally Posted by manojkumar.m View Post
    The player is unable to play the specified file and giving exception as "javax.microedition.media.MediaException: unable to parse the protocol".

    But when I created the player:
    p = Manager.createPlayer("file:///C:/Data/Sounds/<some_fileName>.3gp");

    the above code works.

    Please help me to use DataSource.

    Thanks,
    Manoj.
    i dont get the point why do u want to use datasource since to use the direct input stream can run?
    Last edited by laili_aidi; 2008-10-22 at 10:55.

Similar Threads

  1. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  2. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  3. WAP service problem on Apache
    By bigg_o in forum Browsing and Mark-ups
    Replies: 3
    Last Post: 2005-04-17, 16:05
  4. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

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