I've figured out that the MediaPlayer on Android 4.4.2 seems to fade-in the Audiofile automatically.
I am using the MediaPlayer for playing a Sound that mustn't be faded in.
It worked well with a Smarthpone with 4.2.1, but on another Phone with 4.4.2 the Fading occurs.
I've also had a look at the SoundPool, but it misses the Feature of letting me know if the File is still playing.
Am I able to switch off the automatic fade-in or do I need to use the Soundpool and keep an eye on the length of the Track on my own?
Thanks,
VanDahken
You can try to setAudioAttributes(AudioAttributes attributes) before start playing.
atrs = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.build();
Try to play with CONTENT_TYPE.
I have the same issue. The good thing is that it worked on a couple other Android versions, so hopefully only 4.4.2 has the problem. My first solution I discovered was to use an uncompressed music file... (.wav with data format LEI16) but the music file was way too big.
I also found that the fade-in doesn't seem to happen if you set the audio stream type to STREAM_RING but that's probably not a good idea since it's meant for phone rings.
For my app I only have one critical spot (when the app first starts) where the music has to play without the fade-in, and I was able to get a fix for that. The intro takes a few seconds before the music starts, so what I am doing is:
-prepareAsync() at the start of the intro
-then when prepared, setVolume() to 0f and start()
-then, after a small delay (for my case that ends up being a few seconds: the time it takes for the app's intro to complete), add a seek listener, and seekTo(0)
-when the seek completes, set the volume to the desired value
Related
I am seeing the following behavior when toggling mute in vlcj:
before first playback of mediaPlayer: mediaPlayer.audio().mute() works fine
when playing: mediaPlayer.audio().mute() works fine
after first playback of mediaPlayer (when stopped): mediaPlayer.audio().mute() has
no effect
Problem: I have a mute button in my UI. When pressed, the button icon changes. But when started, the player is not muted, which makes the button show the wrong icon. It seems that you have to wait for the player to start playing before being able to mute it. I could get around this by calling setMute() on the first time-changed event, but it has the effect that even if muted through the UI beforehand, you will hear a fraction of the audio before setMute() takes effect. I have read this post: https://github.com/caprica/vlcj/issues/395 but it's quite old. I was wondering if there are better options now? In native VLC I don't see this issue, but I learned that it is not using libvlc. Is there anything one could do to get around this problem?
The vlcj sample application shows the same behavior btw: play some mp3 file, stop the player, toggle mute and start the player again -> the player is not muted.
setVolume() seems to have the same issue.
Unfortunately, this is just how the native media player in LibVLC 3.x works.
This does work as expected with LibVLC 4.x, and therefore vlcj-5.x, but VLC 4.x is likely still some way off from a full release, it's only available in unsupported pre-release nightly builds at the moment.
There may be some workarounds, but they will not be ideal - e.g. you could manage the mute/volume state yourself and apply it immediately when the media starts playing (listen for a "media player ready" event) - but obviously here you may get a short blip of unwanted (or missing) audio.
Instead of listening for "media player ready", you could maybe try applying the mute/volume on receipt of an "elementary stream selected" event with type audio, but I'm not sure this will work or be any better to be honest.
It may also be beneficial to listen to the various audio-related media player events, you have "muted" and "volume changed", and more recently "corked". At least then you might be able to keep your UI controls in sync with the actual state of the media player, even though it is not quite what you want.
So in short, I'm afraid with LibVLC 3.x there is not a good solution here.
I already asked about it before, but my question even after edits about my progress of fix this noone answered to it anymore. This is original question:
Android media player stop playing while in background
So in short, I'm making music player app, but mediaPlayer stop sometimes when loading next song. After many tests I find out that it stops at mediaPlayer.prepare() and it won't continue as long as I don't trigger any action on phone like turning on display, volume up/down, click headset button. I'm out of ideas what can be a reason of it.
maybe you need to call prepareasync() instead of prepare().
I have been working on an app, and it involves sound.
Now, I use this to start it:
final MediaPlayer tick = MediaPlayer.create(getApplicationContext(), R.raw.tick_16);
tick.start();
But for some reason, after some time (depends on the device, on HTC One it is a few seconds and in others a few minuets) all sound stopps.
What is the cause of it and how can I solve it?
Use this tutorial to play audio :
http://www.tutorialspoint.com/android/android_mediaplayer.htm
you may be use tick.start(); in onResume() method of your activity class
Try starting the MediaPlayer in a Service and a Notification inside startForeground().
I have a quick and dirty solution that might not work on android versions 2 and up.
The problem involved music preference (true or false) and loading the music. Basically, if the music preference was off, and then the user turns it on, the music loads in another thread but the function also calls play_music() right away. But the music doesn't play since it takes a relatively long while to load the music and the play_music() function called and ended. However, if then user turns off the music then turns it back on right away, the music plays since it's already loaded.
To get around this, I continually called this piece of code in the update method:
if (scr_get_pref_music() == true && Assets.msc_song != null)
{
Assets.msc_song.play();
}
It works on my android phone (version 4.04), but I wanna know if continually calling the play() function will cause any glitches or stuttering music in other versions of android (2 and up).
thanks
This might help you,
int status = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
If it is enabled, status== 1, otherwise status== 0.
Atleast it works for me.
I am developing application similar to Music Player.
I am using Mediaplayer in android.
I am unable get those effects please help me on this ....
Actually I want to create an equalizer from which I can change the reverb & tone values of music, which MediaPlayer is playing.But I am not getting any way to do it.
Platform : Android
Waiting for response.....
It can be done in 2 ways
One before creating the media player instance you can attach them by creating spepcifc set of profiles
- http://developer.android.com/reference/android/media/MediaPlayer.html#attachAuxEffect(int)
After creating mediaplayer, you can still create new aux and you need give mediaplayer's id with it. You need to set session id for mediaplayer before doing setsource. - setAudioSessionId
Krishna