Android studio check if Mediaplayer is playing in a screen widget activity

All we need is a simple explanation of the problem, which is provided below. There’d be a button on the home screen which would play a certain song and change the background image of the button. If the user clicks on the button again (when the music is playing) then the music should stop and … Read more

Stopping previous item in RecyclerView MediaPlayer

All we need is a simple explanation of the problem, which is provided below. I have a RecyclerView in which each item contains a button that plays sound from online url. The problem is that I don’t want the items to play sound at the same time and when you click on different sound, the … Read more

Android "visibility" doesn't change if next instruction take long time

All we need is a simple explanation of the problem, which is provided below. I have following situation in my fragment. @SuppressLint("ClickableViewAccessibility") override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { val view = inflater.inflate(R.layout.streaming_fragment, container, false) val button = view.findViewById<Button>(R.id.radio_button) val pb = view.findViewById<ProgressBar>(R.id.progressBar) button.setOnClickListener { if (mediaPlayer.isPlaying) { this.mediaPlayer.pause(); } … Read more

How to set a new audio data source for Android MediaPlayer in Kotlin

All we need is a simple explanation of the problem, which is provided below. New to Android and Kotlin… I am trying to set a new audio data source for the Android MediaPlayer. The below code compiles and runs, but the sound isn’t played. No crash, no errors. The toast "Media Player prepared!" never shows … Read more

Why do I get NullPointerException when trying to instantiate Mediaplayer? Android Kotlin

All we need is a simple explanation of the problem, which is provided below. package com.oyly.gpsdemo import android.content.Context import android.media.MediaPlayer class SoundGenerator(context: Context) : MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener { private var mediaPlayer: MediaPlayer = MediaPlayer() private var nextSound: Int = R.raw.coast init { try { mediaPlayer = MediaPlayer.create(context, R.raw.coast) } catch (ex : Exception) { println("lyseoy11: $ex") … Read more

How to check MediaPlayer is ready to call start() | Android Kotlin

All we need is a simple explanation of the problem, which is provided below. I want to check if the prepare() is finished to call start(),Because I sometime when I press the start button it starts playing but I can’t pause or stop the player. Now: I need to wait for a while to make … Read more

MediaPlayer not playing after reopening the app

All we need is a simple explanation of the problem, which is provided below. When i add mediaplayer.start in onResume i was expecting to start the audio when i reopen the the app but it dindt start it public MediaPlayer mediaPlayer; int length = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mediaPlayer = MediaPlayer.create(this, … Read more

Playing audio in the background more than one minute on Android

All we need is a simple explanation of the problem, which is provided below. I am in the process of developping an Android app handling audio data, now seeing how to have the audio keep playing when the app is in the background using a service. At this point I can set a service playing … Read more

Android MediaPlayer continues playing after screen is turned off

All we need is a simple explanation of the problem, which is provided below. I’m trying to follow the Core App Quality guideline FN-A1 that says that audio shouldn’t play when the screen is off, so I checked it, and it does continue playing after I turn the screen off, but I’m not sure why. … Read more

App stops working when mediaplayer is stopped in Service Class

All we need is a simple explanation of the problem, which is provided below. I am making a media player which plays music using an URL. I implemented a foreground service and also a notification. They are working fine. The problem is when I implement .stop function in media player , which is (rathu.stop)in my … Read more