views:

133

answers:

1

Hi,

I am developing an application which let users to hear songs online. And I used Blackberry Player and Manager APIs. My application works fine and I can play songs. Now I wan't to add more controls to it. As an example I want pause, play songs. Mute the sound, Control the volume. Display the progress of the play back. Display the current time position of the song like that. I started research on that. And I tried to do that with PlayerListener. But unfortunately all the time I am getting IllegalStateException. So I can't go ahead with that research.

As a help can someone please tell me how can I implement above kind of controls for a player. Appreciate if someone can post a sample code to do that. Further I will put my playback source code here.

public void run() { try { p = Manager.createPlayer(requestedSong + SystemSettings.strNetwork); p.setLoopCount(1); p.start(); } catch (IOException ioe) { } catch (MediaException me) { } }

public void run()
{
try
{
p = Manager.createPlayer(strSongURL);
p.setLoopCount(1);
p.start();
}
catch (IOException ioe)
{ }
catch (MediaException me)
{ }
}

Thank you very much.

Prasad

A: 

As they always say, have a look at the MMAPI docs. forum Nokia has good examples of this for the MMAPI.

But first you can check your code by adding:

p.realize();
p.prefetch();

To pause / stop the player call p.stop().

To get the current position call p.getMediaTime(); To get the full duration of the file call p.getDuration();

From those you can calculate the progress.

To control volume:

import javax.microedition.media.Player;
import javax.microedition.media.Manager;
import javax.microedition.media.*;
import javax.microedition.media.control.VolumeControl;
private VolumeControl vc;


public void changeVolume(int diff) {
    VolumeControl vc;

    if ( p != null) {
        vc = (VolumeControl) p.getControl("VolumeControl");
        if (vc != null) {
            int cv = vc.getLevel();
            cv += diff;
            cv = vc.setLevel(cv);
        }
    }
}

Define your player class to implement runnable, and control it in its own thread.

Have a look at: http://www.java-tips.org/java-me-tips/midp/

Hope this helps.

Volume values are from 0 to 100.