Android Question How to play youtube video in ExoPlayer

sentechnologies

Member
Licensed User
In ExoPlayer, i can able to play youtube video using the following code
B4X:
ExoPlayer.Prepare(ExoPlayer.CreateDashSource("https://youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,As&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0"))

but , when i played using the following code
B4X:
ExoPlayer.Prepare(ExoPlayer.CreateDashSource("https://youtube.com/watch?v=T6vELKGu-GA")
i got the following error.
B4X:
com.google.android.exoplayer2.upstream.HttpDataSource$InvalidResponseCodeException: Response code: 404

please help me how to covert youtube video url to play in ExoPlayer
 

drgottjr

Expert
Licensed User
Longtime User
you need the so-called "video information". start here:
https://www.b4x.com/android/forum/threads/exoplayer-youtube-dash.75195/#content
you'll start with "v=T6vELKGu-GA", extract the video information, parse it and back yourself into the long url form you are familiar with.
(note: the easiest way is to get the free youtube api key and play the video in its own view. you can switch back to the exoplayer view for your regular videos. if a video provider whose videos i want to see only broadcasts on youtube, my app just switches from exoplayer to youtube player. works fine.)
 
Upvote 0
Top