I'm wondering how can we get pause,play and upto how much user seen the video data from the youtube player api ?Is this possible to get those details ?
For getting current time : getCurrentTimeMillis()
For moving the video to the time indicated: seekToMillis(int milliSeconds)
To plays the selected video : play()
To pause the video: pause()
And to get info maybe the best option would be use JSON
Related
Example: I have a Spotify album and I want to play its 15th track. After track 15 is finished playing I want Spotify to play track 16, after that track 17 and so on.
I am using the Spotify App Remote SDK for Android. I can think of three possible solutions.
Solutions:
Get the following tracks of the album through the Spotify Web API and add them to the queque. This one does not work for me though because I do not want Spotify to keep the queque when the user starts playing another playlist or album.
Use a background service that automatically starts playing the next track when the current one is finished. But here the user can experience a significant delay between the tracks.
Start the album and skip multiple times. This option would theoretically work. It does not seem to be a very elegant though.
Is there a better way to achieve this? Like for example somehow adding a context to the track? Thanks for any help!
There is a good sample code Start/Resume a User's Playback how you can achieve it.
{
"context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
"offset": {
"position": 5
},
"position_ms": 0
}
Set the context_uri to your album id, and offset to your track number and position_ms to your position in milliseconds.
With the method:
mSpotifyAppRemote.getPlayerApi().skipToIndex(java.lang.String uri, int index)
you have to put the uri with the context, for example an album:
"spotify:album:5ht7ItJgpBH7W6vJ5BqpPr"
and in the prameter index you need to put the position of the track in the album.
You can find more methods in the javadocs of SpotifyAppRemote here:
https://spotify.github.io/android-sdk/app-remote-lib/docs/
I am making a media player where I am showing videos from the remote server(e.g. youtube). I have shown a list of videos but I am unable to get the length of videos.
(I have searched on this site but I got answers regarding how to get time duration of the video which is locally stored.
I am giving the link to one of such question.
How to get length in milliseconds of video from URL without video view in Android?)
MediaPlayer mp= new MediaPlayer();
mp.setDataSource(context,uri);
int durartion = mp.getDuration();
I am working on an application that has media playing features.
I would like to honor AudioFocus. I first request AudiFocus:
audioManager.requestAudioFocus(new CustomOnAudioFocusChangeListener(), AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
This call returns either AUDIOFOCUS_REQUEST_FAILED or AUDIOFOCUS_REQUEST_GRANTED.
I guess I shouldn't start playback if I receive AUDIOFOCUS_REQUEST_FAILED. But then what to do?
Will my CustomOnAudioFocusChangeListener be notified when focus becomes available or is it only when you got AUTOFOCUS_REQUEST_GRANTED that it starts getting updates?
Should I inform the user and ask him to try again later? Or retry programmatically after some time?
Thanks in advance
What to do depends on how you want your app to react. You shouldn't start playing, you may want to message your user. Or if its something non-critical, you may silently ignore the failure and move on.
I believe you only get updates on the listener on success. You get the updates then so if you're lowered you can choose to duck your output or pause until you regain.
How to do I check when a YouTube video has finished playing in the official YouTube Android app? In the LogCat I see things such as: VideoStage: MEDIA_PLAYING_VIDEO. Is there any way to detect when this finishes?
You could use MediaPlayer. It has an isPlaying method to check if music/videos are currently playing. Just set a Boolean to true while it's playing and check the isPlaying method against that Boolean to see if it changed from True to False.
Otherwise Youtube (or google) may have some specific API's
EDIT:
I looked into here; and it appears that there is an API for youtube.
you can use the method PlayerStateChangeListener for the YoutubePlayerclass to get the listener and implement the method OnVideoEnded
i am developing one application which
needs to play an audio song to callee when call is lifted by callee,
and automatically call has to be disconnected automatically when audio
song playing completed . i tried to find in android API for any
classes or methods to do this, but failed to find... please help me
how to do this..
your answer could be helpful to me...please do reply
Thank you in advance..
AFAIK, it is not possible to play a sound in the ongoing call and also to automatically dosconnect a call. Telephont API doesnt provide any methods to do any od these. So both od these requirement can't be fullfilled in ANdroid.