I am developing an application.
Related to my application,
I want to know if any audio song is playing or not in the backgroud through any other
music player apps or the default musicplayer come with mobile.
If anyone knows the solution please help me.
You need to use isPlaying() in the MediaPlayer class.
isPlaying() will return false when the default MediaPlayer application is not currently playing, so you must be using some other music application that we are not aware of. You should probably post your code, if that is the case.
Related
I was wondering how to exactly stop all other music that may be playing when my app is opened whenever there is music being played in my application. I have a couple instances where I just have sound effects, so is there anyway I can stop music that may be playing already whenever these sound effects pop up? I know I'm not giving any code, however, I have no idea how to approach this and haven't found many other questions asking similar things.Thanks!
Look at the AudioManager.requestAudioFocus API. Remember to release the focus when you're done with it, or other apps may not be able to play sounds correctly.
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 making an music streaming application with music player in it. Now i want that users should be able to switch between activities while listening to music in the player. Also i would like to control and display info about the track being played in one activity.
I have tried implementing the MediaPlayer but is stops playing when i navigate to another activity. Any code example or pseudocode is welcome.
Thanks.
The best option for this is Service.., See this Tutorial.You can learn more Here about services
I have a list of music files that should be played with my Android application. Actually user selects a list of files to be played for a specified time, and then clicks on 'start button'. Please tell me how I can implement it so that the following requirements are met:
The program should work, even if power button is pressed or the display is turned off.
Music files should be played one by one.
In order that the music continue after your application activities exit, you need to implement the playing itself as a Service (specifically, a started service). For playing the music, take a look at MediaPlayer. There is a discussion of using a MediaPlayer in a Service in the Media Player guide topic.
To play audio files, you can use Android's MediaPlayer class.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(audioFilePath);
mp.prepare();
mp.start();
This code snippet will load and play a single audio file. Take a look at the documentation for MediaPlayer to figure out how you might be able to leverage it for what you're trying to accomplish specifically.
I have looked into the MediaPlayer documentation for Android, but this seems to be primarily for playing media in a localized media player. I just want to be able to tell if music is playing in Android default Media Player.
Thanks
AudioManager::isMusicActive() Checks whether any music is active.
http://developer.android.com/reference/android/media/AudioManager.html
See if that helps you: http://www.alexc.me/android-music-app-service-currently-playing-song/231/