hi viheaho! looks like we are in the same problem jejeje.
I am currently working with a nokia 6682. So far, i still have the problem of the gap.
By
"how did start the loop over again?" you refer to how i make to coordine the two players to start one when the other ends...no?..
well.. basically i have for one side, a buffer of memory where a threat put data from the web (the .mp3 file) and other thread read that buffer. This buffer is "synchronized" so the while one is reading the other can write and viceversa.
For the other side a thread that pick up the data of the buffer, puts this data on another object that plays the sound, let's call it 2_Player_Reproductor. Here a have two ideas...well i tell you the more structured one. This objetct 2_player_Reproductor implements the interface PlayerListener.
First you store for a first time the data (in 1 of the two players), then you play it. Then you entered a while there is no the end of the mp3 (you can set a while (true) and start with that...there is no need to worry about that condition). Inside the while you read from the buffer one more block of data, and while you doesn't have place to put this data, this means one player (A) is playing the song and the other (B) has already data and it prefeching or realizing it. You put this thread to wait.
When the message END_OF_MEDIA is send to your player listener (2_player_reproductor), inside this callback style function you put to play the other player (B), and "releases" the player that was playing before(A), then i activates the thread that was waiting, then he store the data on the player (A).
I guess it's not very visible, and a matter of fact is quite complicate cuz i guess there are many way to do it... you must control what player (A or B) is avaiable using booleans or another mecanism.
Inside the class that Reads from the buffer, we have the run method that's looks like this..
Code:
public synchronized void run ()
{
buffer.read(data); // read data
reproductor.store (data); // put data inside one of the 2 players, not play it!!!
reproductor.play (); // then i use this method for start playing just once.
while (true && !bCancel)
{
this.buffer.read(data); // read more data blocks
while (!reproductor.haveStore()) // if a have another player where i can put the music...put it...if not, we wait.
{
try {this.wait ();} catch (Exception e) {}
}
reproductor.store (data); // we put that data in one of the two players..
}
}
public synchronized void NOTIFY ()
{
this.notify ();
}
Inside the class Reproductor :
Code:
public void playerUpdate (Player player, String eventDescription, Object object)
{
if (eventDescription == END_OF_MEDIA)
{
this.bPlaying = false;
if (player == player1)
{
this.bPlayer1Avaiable = true;
this.nextPlayer = this.player2;
}
else
{
this.bPlayer2Avaiable = true;
this.nextPlayer = this.player1;
}
try {this.nextPlayer.start();} catch (MediaException ex) {} // Then start the other player...
BufferReader.NOTIFY(); // Remenber you must gain the lock of the object.., you can't use bufferReader.notify ().... instaed you can use synchornized (BufferReader) { BufferReader.notify; }
}
}
It's was really hard to me doing all this....most at all for thinking..i hope it can be understable...and i hope we can reach a common solution.
P.D : The Store method (i forgot jejeje) this method put the data in one of the two players avaible. And realize and prefect, then it modifies the avaiable state of that player. Nothing more. It doesn't play music.
The play method just do a player.start (); where player is the fists player where you put data with the store method.