Android media player stop playing in service - java

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().

Related

How to Reset the seekBar and disable it when another mediplayer is Running?

I have a List of Voice Recordings. Everything works well until, when one MediaPlayer is running and i clicked on another MediaPlayer without pausing the current one, seekbar of the current MediaPlayer also runs with the new MediaPlayer.
I tried everything possible i could from setting certain conditions to it but nothing is really working.
Please anyone there to Help me!

vlcj: player.mute() has no effect when player is not playing

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.

How can I add a soundtrack in multi-windows android app?

Good time of the day! I needed to add a soundtrack, but the problem is that the application is multi-windowed. I looked at the documentation, a video on how to add music, but there is a one-window explanation. Can you explain how to make it so that when the button is pressed, the song is played and transferred to another screen, but that the music continues to play, and stops playing when the user presses the button that takes to the 3rd page - stops playing

Java Android: Mediaplayer fades automatically

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

How can I make background music for android project

I'm making a small android app like image below:
I have a sound button. All I want is background music will play across all activity and when I click on sound button, music will stop. Or click to play music again.
I dont know how to make it. PLease help me! or give me link to refer.
I'd gladly appreciate your help it Thanks!
Hi please Follow below steps
initialized
MusicPlayer object when your app starts MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.song);
set this in your button's click event.
Start it by mediaPlayer.start();
3.Stop it by mediaPlayer.stop();
but when you stopping mediaPlayer before that just check mediaPlayer.isPlaying() with if Condition. then Stop. else error thrown.
or follow this Example Turorial Link
In order for media to be played in the background of your app location when the user is interacting with it you must start a Service from your application's main activity and the service shall contain all the methods related to playback. To allow activity to interact with the service, a service connection is also required. In short, we need to implement a bounded service.
Refer http://www.codeproject.com/Articles/258176/Adding-Background-Music-to-Android-App

Categories