MediaPlayer stops when changing SystemClock.setCurrentTimeMillis(millis) - android

So I have an app that plays a video.
And I have a time sync server for setting the datetime of the device. It seems that whenever I call SystemClock.setCurrentTimeMillis(millis) the video stops.
I am using android.media.MediaPlayer.MediaPlayer() object to play the video?
Has anyone else experienced this? I was planning on creating a watchdog thread that just monitors the current duration. But just wanted to know if anyone had come across this already?

Yes, I came across the same situation on some devices. Probably hardware libs use the system time clock in the in decoding or av sync implementation; it happens. Only solution on those devices was to stop/restart the MediaPlayer. But it probably depends on the implementation of the lower levels.

Related

Change the pitch of the sound but not changing its playback speed unity3d

I am just developing a sample app in unity (as a beginner) so i am stuck at a point, i need to change the sound which is recorded (like in Talking Tom app).
i am done with recording the audio but when i increase the pitch of the sound the speed of the playback is also changed. i need the playback speed is normal only pitch must be changed.
so can anyone help me on this issue.
Thanks in advance
After a bit of researching, I found that what you're trying to do is called "pitch shifting". It involves a lot of math and mucking about with sound packets apparently because changing the pitch of a sound, automatically changes it's playback speed. Getting it back to the speed you want while still keeping the audio at something considered "normal" is no walk in the park.
In any case, since Unity3D uses C#, you might (and I stress the word might) be able to use this open source library to get the sound effect you need. It's based on NAudio (also open source, and C#) so you should theoretically be able to use it, or parts of it in your project.

Android audio delay - how to calculate delay

i understand that there are some issues why android can't ply low latency audio and has a >100ms delay on everything (well.. actually vibrations are faster as audio!!! Shame on you!).. but is there some possibility to figure out how much earlier i need to run the sound to actually be on time?
e.g. how to calculate audio delay?
Im creating a rhythm game and i need to play "ticks" in sync with music.
Im using libGDX Sound - e.g. sound pool - play() now.
Any suggestions?
Your app could emit a sound with the speaker and then use the microphone to detect the sound emited by itself (something similar to remote.js).
Even though there are many variables involved (the mic will also have a latency), you can make the device calibrate it self by continuously trying to guess how long the sound will take to be detected, and emiting it again and again until your guess gets "fine tuned".

How do I stop the sound restarting when a collision occurs

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.

Android Gingerbread buffering with MediaPlayer

I try to implement a simple media player to play an audio stream from an external URL. Pretty simple I guess. Tried to implement this sample from Androïd dev site http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/media/MediaPlayerDemo_Audio.html
It works just fine with 2.1.
Then, with 2.2 it gets weird. Starts just well, but takes almost 10 seconds to stop.
With 2.3, it's not better. This time might take up to a minute to start playing, but stops OK.
Does anyone have a clue why ? I also did try the prepareAsync way with the listner, but it never get called. Any help would be appreciated at this point. Thanks !
Register setOnInfoListener() and control start buffering, end buffering and so on.
Look at the android documentation link

Android MediaPlayer causes game to freeze with "AudioHardware pcm playback is going to standby"

This is a tough one :/
I'm making a music-based Android game a la Audiosurf. It works all nice except a few seconds before end of a song (that is being played with a normal MediaPlayer) the music stops aprubtly and the whole game (including UI) freezes for several seconds.
Each time that happens I see an "AudioHardware pcm playback is going to standby"-error in logcat.
Googling has led me to the conclusion that
this could be a HTC Hero specific issue (cannot be reproduced on emulator or other devices)
this message is normally logged when a http stream isn't fast enough for MediaPlayer
Audio in Android sucks in general
As I am decoding the mp3 with the NDK + libmpg123 for audio analysis already I might aswell just play the audio myself (using a very ugly interface between NDK C code and an AudioTrack in Java).
Is there a fix/workaround for this bug or should I really go that way? (I only have limited time left to complete this project)
I appreciate every hint!
You might be stopping the music when you've buffered it all in your C code. Since the AudioTrack has a delay in it, you may need to wait longer for it to finish.
I'd need more detail about your code to help, though.

Categories

Resources