5

I want to play video from YouTube on my app but with custom media player controls as following:

enter image description here

It works if I put those buttons on a separate layout below the player, but I need to overlay the layout which YouTube doesn't support (except for ActionBar). How can I modify the Android player to meet my needs? Is it possible to use different media player (with VideoView) to play YouTube videos/playlists? Or can ActionBar be used to include those media controls including SeekBar? Please suggest.

ozbek
  • 20,955
  • 5
  • 61
  • 84
asok Buzz
  • 1,876
  • 3
  • 24
  • 50
  • ***?? I was stuck in just 3 views for 2 days?? what is this?? aren't there any youtube guys here to help?? even single comment would guide.. is #stackoverflow dead already? – asok Buzz Jul 15 '14 at 10:44
  • Update your tag. What is langage do you with youtube-api ? Javascript ? – user2226755 Jul 16 '14 at 15:29
  • Possible duplicate - http://stackoverflow.com/q/12482203/2164198 - Check http://w2davids.wordpress.com/customized-android-media-player/ also – Ivan Samygin Jul 17 '14 at 17:43
  • that is about mediaplayer, I need the features over android player. – asok Buzz Jul 18 '14 at 04:58
  • 1
    I'm afraid there is no way to achieve what you want using the [YouTube Android Player API](https://developers.google.com/youtube/android/player/). Here is a quote from the [YouTubePlayerView](https://developers.google.com/youtube/android/player/reference/com/google/android/youtube/player/YouTubePlayerView) document: "Also, it is not permitted to overlay the view with other views while a video is playing." – Alan Jul 18 '14 at 07:00
  • But how about using chromless mode and putting those button on actionbar? – asok Buzz Jul 20 '14 at 05:19
  • 1
    I think you can use action bar to include the whole View using `actionBar.setCustomView(view);` is that what you are looking for ? – Omar Albelbaisy Jul 20 '14 at 16:38
  • Yes exactly. I want actionbar at the buttom (containing media controls). How is that possible? – asok Buzz Jul 21 '14 at 05:33

3 Answers3

0

You can stream youtube videos through the android MediaPlayer if you have the direct link to the YouTube video.

This source suggests that the direct link can be retrieved using the Google Data API.

Then to customize the the controls you would need to extend your own custom MediaController class which is covered in detail here.


Another way I can think of is to use local html file (from your assets) to display the video inside a WebView. With the help of JQuery it's controls can be tweaked.

Here's an example in JFiddle that uses jquery and css to style the video: JFiddle (alt link)

However note that this method might not be compatible with older android versions as WebView upgraded from WebKit to Chromium not too long ago. The old WebView had a very poor compatibility with HTML5 and videos in general.

Community
  • 1
  • 1
Simas
  • 43,548
  • 10
  • 88
  • 116
0

Alternatively, you can use ExoPlayer and customise controller view:

<com.google.android.exoplayer2.ui.PlayerView  
   android:id="@+id/video_view"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   app:controller_layout_id="@layout/custom_playback_control"/>

XML layout Example :

https://raw.githubusercontent.com/google/ExoPlayer/release-v2/library/ui/src/main/res/layout/exo_playback_control_view.xml

For more info read this guide:

https://codelabs.developers.google.com/codelabs/exoplayer-intro/#6

Hitesh Sahu
  • 41,955
  • 17
  • 205
  • 154
-1

you can refer below link, you have two choice first download *.jar then import to your android project and run, another check out source from svn server and modify to your want.

https://code.google.com/p/android-youtube-player/

Addition

...    
intent.setClass(MainActivity.this, OpenYouTubeActivity.class);
startActivity(intent);
whck6
  • 59
  • 6
  • I need custom mediaPlayer controls not default – asok Buzz Jul 21 '14 at 05:35
  • yes i know, so you can check out source then modify to you want. because i see you said "I want to play video from YouTube" about this problem need specific way. – whck6 Jul 21 '14 at 06:45