Converting YouTube URLs to work with ExoPlayer Android integration

I’m working on an Android app and need to integrate YouTube videos with ExoPlayer. The problem is I only have standard YouTube links but ExoPlayer seems to need a different format. I found some examples that use special manifest URLs but I can’t figure out how to convert my regular YouTube links to the right format.

Here’s what I’m trying to work with:

MediaItem videoItem = new MediaItem.Builder()
    .setUri("https://example-api.com/manifest/stream/id/abc123xyz/platform/android?"
    + "format=mp4_audio,mp4_video&params=device,quality,timestamp&device=mobile&"
    + "quality=hd&timestamp=20000000000&token=ABC123DEF456GHI789JKL012MNO345." 
    + "P6Q7R8S9T0U1V2W3X4Y5Z6A7B8C9D0E1F2G3H4I5J&auth=xyz789")
    .build();

But my actual video URL looks like this:

https://www.youtube.com/watch?v=abc123def456

How do I bridge this gap and make regular YouTube URLs work with ExoPlayer?

yeah this is a common headache for android devs. youtube basically locks down their streams so you cant just plug urls into exoplayer like that. ive seen people try using yt-dlp or similar tools but its against youtubes tos and they keep breaking those methods anyway. your best bet is probably just using the youtube iframe api or webview approach if you need youtube specifically.

Unfortunately you cannot directly convert standard YouTube URLs to work with ExoPlayer because YouTube doesn’t provide public streaming endpoints for their videos. The manifest URL in your example appears to be from a custom streaming service, not YouTube itself. YouTube’s Terms of Service explicitly prohibit extracting video streams for use in third-party players. What you’ll need to do instead is either use YouTube’s official Android Player API which provides the YouTubePlayerView component, or consider hosting your videos on a different platform that does support direct streaming like Vimeo Pro, JW Player, or your own media server. If you absolutely need ExoPlayer’s features, you could look into YouTube Data API to get video metadata and thumbnails, but the actual playback would still need to go through YouTube’s official player. Some developers have tried using unofficial libraries to extract YouTube streams but these violate ToS and break frequently when YouTube updates their systems.

I ran into this exact issue about two years ago when building a media player app. The harsh reality is that YouTube actively blocks direct stream extraction, and any workaround you find will be temporary at best. I initially tried using libraries like youtube-dl-android and NewPipeExtractor, but they broke constantly due to YouTube’s frequent API changes. After wasting weeks on this approach, I switched to embedding the official YouTube Player API alongside ExoPlayer for other content sources. This hybrid approach worked much better - YouTube videos play through their WebView-based player while everything else uses ExoPlayer. The user experience is actually quite seamless since you can style the YouTube player container to match your app’s design. If you’re determined to use only ExoPlayer, consider migrating your video content to platforms like Cloudflare Stream or AWS CloudFront which provide proper streaming URLs that work reliably with ExoPlayer.