Does anyone know where this exception come from, I just making a game and every click has a sound, isn't a problem for sounds to interfere? I created a class call playaudio importing audioplayer and audiocache with play and pause methods, and instantiate it when I need it.
Note: this error is happening rarely, because I'm using Timer to automate the game so it happening just in some points.
Flutter audio player Exception
My playaudio Class
Update:
I was facing this error because I was automatically runs multiple sounds in the same time, after adding some conditions lines to dominate one sound upon others, for example to prioritize win sound effect upon the restart sound effect like:
if (!win){
play(restartSound)
}
That's what solved my problem.
Related
I am playing some background music in my PlaynN game. Everything is fine except it does not pause when the activity is sent to the background. Music still plays when the game is not playing.
I can use Sound.stop() and Sound.play() whenever the window focus changes but then the music restarts from the beginning. I can instead use setVolume(0) and setVolume(1), but it still doesn't sound the way it is supposed to.
I cannot find a working example. I am currently considering the use of a platform specific music player.
Many thanks
To my knowledge, PlayN doesn't support pausing/resuming a Sound, probably because not all platforms support this. However, you might want to take a look at the Android-specific implementation of AndroidAudio, which seems to use a SoundPool backend. The GameActivity seems to already pause and resume sounds when the window gains/looses focus, so I'm not sure why it's not working for you - I believe it has for me. You might try calling these methods manually to test that they work, and if not consider filing an issue.
So I've been working on a music player for Android and I've run into a problem I'm having trouble fixing. When the user starts a song, I store the currently playing song in a public variable in my "Player" class. This is used to determine what song to play next, among other things.
The problem is that the app sometimes crashes when the user opens a lot of other memory intensive apps. The MediaPlayer stops playing, and the reference to the currently playing song is lost. I'm pretty sure this happens because these other apps claim the memory that my app was using.
My question is: How can I make sure the MediaPlayer always keeps on playing? The standard Android music player doesn't seem to have this problem so it should definitely be possible to keep it playing at all times somehow.
The best you can do is host the MediaPlayer in a foreground Service.
i am facing a problem. when i am using Audiorecord function,some music App is still playing and some gets pause immediately.
i've used the mAudioManager.requestAudioFocus() and also use mAudioManager.abandonAudioFocus(). but it seems doesn't always useful in some situation.
is there another method to solve this problem?
Currently my code plays a sound when there is contact between any objects in my game using andEngine and Box2D and the walls, the problem I have is that when contact is made with any objects it starts again I understand why this is happening. What I want to do if possible is keep playing the sound while also playing it for another collision. I think I may need to use threads but I am unsure how to do this in java for android.
#Override
public void beginContact(Contact contact)
{
Rattle.this.mExplosionSound.play();
}
UPDATE: I don't seem to have been able to fix the issue but I know that what I need to do is play this sound multiple times simultaneously, I have tried threads and the soundPool but got no luck with either still not sure what to do.
It seems you have only one instance of the sound. Then you call play on the same sound twice, therefore it stops playing and starts from the beginning.
Imagine having one CD player - you press play, the music starts to play. You press play again and the player starts reading the track from the beginning. What you need is two players, therefore you may need two instances of the same sound.
(I don't have much experience with sound on Android so I may be wrong, please take the advice with a grain of salt.)
Even I was developing a game some time back and I found a similar problem. You should use SoundPool to play short sounds like crashing and collisions. here are some good linkswhich helped me. Link 1, link 2.
I've been doing some pretty complex things with the MediaPlayer. Unlike https://stackoverflow.com/questions/7399286/android-media-player-internal-external-state-mismatch, I'm only working with audio, not video. The MediaPlayer class is notoriously fragile and unintuitive, so it's difficult to work around its quirks. I've been doing the best I can, but still run into difficult-to-diagnose bugs.
In this case, I occasionally see the error message "internal/external state mismatch corrected". I have no idea why. I'm running multiple MediaPlayers simultaneously, using MediaRecorder and then playing it in a MediaPlayer, stopping and starting and resetting and seeking... at least some of the time it seems to occur after start().
Is this a bug in Android, or am I doing something wrong? Can anyone tell me what this error message represents, and if there's something I should be doing differently or if I can safely ignore it?
Not sure that answers your question, but looking at the source code, it seems like the state was MEDIA_PLAYER_STARTED although the player stopped playing already, and Stagefright changes the state to MEDIA_PLAYER_PAUSED.
There's seem to be an open bug for that: http://code.google.com/p/android/issues/detail?id=9732
I got the "internal/external state mismatch corrected" errors to stop by calling MediaPlayer.reset() immediately after instantiating the MediaPlayer object:
MediaPlayer mp = new MediaPlayer();
mp.reset();