Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

BlackBerry® World™ Development

Reply
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified
Accepted Solution

Time Lapse in playing audio files

Hi all,

 

              i need to play two different audio files one after the other. in detail file1.mp3 is to be paused for a  while and file2.mp3 is to be played immediatly without any delay and after completing it file1.mp3 should be played.

 

my problem is file1.mp3 is playing untill file2.mp3 is invoking, after a time lapse file2.mp3 is playing and then file1.mp3 is not continuing to play how can i fix this issue,

 

this is my code to play the files. am sure they are playing,

try{
player1.stop(); // it is stopping

player2.start(); // file is playing but with a time lapse. it is a file of duration 1sec

player1.start(); // not continuing to play
}

 

but with a time lapse.

 

 

 

Thanks and Regards,

Praveen 

 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Time Lapse in playing audio files

blanc,

 

After you call player1.stop(), call player1.setMediaTime( -1).  This resets the player to the beginning.  Some blackberry models and OS's automatically resets to the beginning after you call stop but I know for sure that the STORM 4.7 does not.

 

try { player1.stop(); // it is stopping player1.setMediaTime( -1); // Rewind the sound so it will play from the beginning. player2.start(); // file is playing but with a time lapse. it is a file of duration 1sec player1.start(); // not continuing to play }

 

It looks like we want to achieve the same thing.  Have a game with background music and sound FX.  I can share my experience with you.  It seems like the sound API for the blackberry is very buggy.  For high action games (like one that I am currently making), I notice that if you have a lot of sound FX, the game just freezes.  I even added code to loop through my hashtable of sounds and make sure all of them are stopped before playing a new one and sometimes it still freezes. 

 

I really don't want to use the Alert.startAudio() because you can only make pacman sound effects but it looks like it may be the only way to go if you are making a game where you don't really know when a sound can be played.  If you were making a board game, then that is different...you can pretty much control when a sound is played or not.  You know what I mean?  Let me know if you experience these issues...

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Time Lapse in playing audio files

[ Edited ]

Hi Lord,

 

As you experienced i also faced the problems with audio files. after adding audio files my thread becomes slow and sometimes it just freezes. after completing the time it just displays the closing screen. now it became buggy..!!!! it is going to IllegalStateException at runtimes.

 

Ok, i tried with what you said... but still no enjoyment!!!!! the problem is not yet fixed with the Player class.. i used player1.setMediatime(-1), after i stopped the player. but not working.

 

As you said i tried with Alert.startAudio(), it is working fine. but i need to pass frequency as one of its parameter.... how can i give the frequency of my mp3 file . actually i tested with some frequency of 100, 200 and so on.. it is generating some audio randomly. so if i give the frequency of my mp3 file the issue is solved for me. is there any way for that???

 

please let me know how to give that frequency value.

 

 

Thanks and Regards,

PraveenG 

Message Edited by Blanc on 08-25-2009 11:01 AM
Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Time Lapse in playing audio files

I'll have to test the setMediaTime( -1) on my Storm but I know this works on 4.2.1 OS's.  I develop my games on OS 4.2.1 as a baseline and then modify them to work with the higher models up to the Storm..or Tour.

 

Alert.startAudio() cannot play any audio files.  That's why I was saying it can make cheap pacman sounds.  It takes frequencies and durations.  For example:

 

short[] cheapSound = {1300, 10, 1250, 20, 1300, 10, 1250, 20}; try { Alert.startAudio( cheapSound, 100); } catch(Exception e) { System.out.println( "Error:" + e.getMessage()); }

 

 

Currently this is the only option if you want to play sound effects while playing background music (The background music can be loaded from a file--I tried with a MIDI file) on the Storm. 

 

So your options are:

 

1.  No Sound 

2.  Cool background music with no sound effects

3.  Cool .mp3 or .wav sound effects and no background music

4.  Play both cool background music and cheap pacman (Audio.startAudio) sound effects

 

Let me know which one you decide..just curious.  I think I may give these options to my user...

Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Time Lapse in playing audio files

[ Edited ]

Hi Lord,

 

i dont know what to say about setMediaTime(-1) it is working or not working... because it is working at randomly.

this is my code....

private class DrawThread extends Thread
{
private boolean _running;

public void run()
{
_running = true;
try {

volumecontrol.setLevel(80);
Audio.audioplayer[_index][0].start();
} catch (MediaException e1) {
e1.printStackTrace();
}
while( _running )
{
// some code
}

}

} // when the thread starts it is playing nicely. this thread is called after cetain intervals of time placed in a timer actually.



// when am trying some thing like this is it is not playing

protected void startNewSound()
{

player1.stop();
player1.setMediatime(-1);
player2.start(); // this file is of millisec duration
player1.start(); // it should play continuously
}


// this is the issue now am stucked with

 

 

I didnt get the exact reason why it is not playing when i stopped and played it immediately. if possible please find this link.

 

            http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=47678  and observer what MSohm is saying.

 

                     Finally from your choices, personally i like a cool background sounds

 

 

Thanks and Regards,

PraveenG 

 

 

Message Edited by Blanc on 08-26-2009 01:02 AM
Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Time Lapse in playing audio files

       Hi Lord,

                          how can i make my manager to move from bottom to top slowly as if it is animating. is there any support for animation in rim package. if there please let me know them.  i mean classes to make tranformations, translation, inversions, rotations and so on.... i found the support is with in the javax.microedition.lcdui, and javax.microedition.lcdui.game, but i didnt find how exactly we make use of these classes in our rim package.

 

 

 

 

Thanks and Regards,

PraveenG 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
New Developer
AntaresTech
Posts: 1
Registered: ‎09-16-2009
My Device: Not Specified

Re: Time Lapse in playing audio files

Hello Lord,

 

I'd love to connect with you directly, as you seem to know a good deal about audio and gaming.  I'm a game audio developer currently helping Antares Technology (makers of Auto-Tune) explore the mobile game space.  You may notice that their iPhone app, "I am T-Pain" is holding steady in the top 5 list after almost two weeks. We're looking at creating Blackberry titles as well.  I'd love to chat with you if at all possible.

Thanks! 

Please use plain text.