Restoring Android Activity playing media - android

I'm working on a project that includes a media player. All is going fine, I select the media to be played from a play list and send it to the player activity and press play. The audio plays just like it should. Now, when I leave that activity (with the audio still playing) I'm unable to get back to that same activity, clicking the same item from the playlist starts a new activity with the old media playing in the background still. How can bring back an old activity?

I don't get your question at all. However, look at the state diagram here:
http://developer.android.com/reference/android/media/MediaPlayer.html
And the other state diagram here:
http://developer.android.com/reference/android/app/Activity.html#ActivityLifecycle
Combine the MediaPlayer states and the Activity states in order to fulfill your need.

Related

What is a proper way to connect with a media browser who is currently playing audio?

I am currently working on an app that includes an audio media player. What I want to accomplish is to start a track on a fragment that represents the UI of the media player (like a bottom collapsed media player), and then when I click on this media player layout, I want to start an activity that will display the media player expanded (including skip buttons and progress bar). Right now, whenever I click on the above-mentioned layout, the activity starts but the track starts all over again instead of resuming. Summing up, I would like to ask if there is a proper way to connect with the media browser in another activity without causing the playlist to start from the beginning. Thank you in advance

Android Youtube like video player running across activities

I need to implement a youtube like behavior video player. If user clicks back while on the player activity and video is playing, the desired behavior is:
kill current activity
show a mini floating player on the previous activity
seamlessly continue playing from same position on the floating player.
This can be achieved with passing the position while moving from one screen to another, but the player will have load from scratch and lose all the buffered (cached) data.
What are the common patterns to achieve this continuous playing of a video? (keeping a static instance of the player? launch a service that hold the player?)

MiniControllerFragment for MediaPlayer application as like Cast SDK

I'm developing a MediaPlayer application which plays videos and want to show mini controller at the bottom of every screen while something is playing.
Question
I want to show mini controller at the bottom of every screen while something is playing, you can refer application like Spotify, google play, and other music applications.app
MiniController that appear when the user navigates away from the current content page. The mini controller provides instant access and a visible reminder for the current mediaplayer is playing or not.
I just checked cast sdk codelabb and found this. It has MiniControllerFragment which manages everything for cast session. Is there any MiniControllerFragment for mediaplayer application so I can show MiniController at bottom of every page when my application does play any video.
Please provide your valuable inputs on this.

Youtube controls (play/pause) don't work after player is restored/activity is resumed

I have an activity with a YouTubePlayerSupportFragment within it to play youtube videos.
The youtube player's style is set to CHROMELESS (only video, no controls), and playback is controlled by my own custom play/pause button outside of the player's view. Every thing works as expected until the moment I leave the video activity for whatever reason and then come back to it.
Upon leaving the activity the video is paused - as expected - but after returning to it, requesting the player to player.play() does nothing. No errors nor exceptions, it just does nothing. Play() will only work again after I load a new video..
I've trying using YouTubePlayerFragment instead, but the result is the same. However, when using the DEFAULT style pressing the default play button will apparently reload the video (I see the buffer being flushed) from the previous position and work as expected. This leads me to believe that they're handling it somehow directly on their UI control code instead of on the player API..
I can reproduce this issue on the SDK's custom controls sample just by starting a video, pressing the recents key and returning to it so I think it's safe to assume that this is a bug..
Has anyone been able to work around this issue? is there any way to detect that the video needs to be reloaded while this isn't fixed?
Info: I'm using youtube's android player API v1.2.2 and the latest youtube app v10.49.59
After hours, the only solution I found was to save video position on Pause event and reload video (player.loadVideo) on PostResume event (when YouTubeFragment is resumed). But I don't known if this is the only/best solution.

Background Music Player While Switching Between Activities in Android

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

Categories

Resources