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?)
Related
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
Video pause if application goes in pause state while using youtube Video Player API in android my app.
But in youtube android app different behaviour. it keep playing video even in app in pause state.
Is it possible to provide same support in youtube sdk for android app develoment
I am using Multiwindow
Case 1# Two application is opne in Multiwindow Mode
1-youtube
2-conatct
when I tap on conatct app youtube is in pause state and conatct app is in
resume state still youtube video kepp playing
Case 2# Two application is opne in Multiwindow Mode
1-MyApp(with Youtube API)
2-conatct
when I tap on conatct app MyApp is in pause state and conatct app is in
resume state still MyApp video stop playing.
So My application is in pause state and vsisible.
So how to handle myapp so it will work like case #1
Your question doesn't provide a lot of information, but here are the different scenarios that can happen.
Case 1: Activity paused and not visible
Playing a YouTube video when the video itself is not visible (meaning: playing the audio of the video) is against YouTube terms of service. Audio and video cannot be separated.
Therefore playing a video when the Activity is not visible is not possible with the official video player API.
You can do it with this library: Android-YouTube-Player. It allows you to decide when and where you want to pause or play your videos.
But again, even if you can do it, doesn't mean you should. Separating audio and video is against YouTube terms of services, so you won't be able to publish your app on the PlayStore.
Case 2: Activity paused and visible
If the case you care about is when the Activity is paused but at the same time visible, there's no problem. You can use the player you prefer, just change your code so that the video doesn't pause when the Activity pauses.
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.
I want to make video player with next option to keep playing video after rotate device.
I created service with MediaPlayer and set SurfaceHolder of SurfaceView after rotate sceen. It works only for Android 4.x. For Android 2.3.X after replace second call setDisplay user doesn't see video, but hears sound of video.
Could you give me direction or example how to implement this option at custom player?
PS. Player shows streaming video.
Okay, I've found solution. It's so easy. I set configChanges="orientation|screenSize" for activity with custom player. In this case activity won't be recreated after rotate device it's changed on the same instance.
As result, I don't need service for keeping MediaPlayer and don't need replace SurfaceHolder.
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.