Issue
In a native (Java) Android app I am attempting to open a URL which is a Youtube video.
final Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(formattedUrl));
context.startActivity(Intent.createChooser(intent, context.getString(R.string.show_title)));
I've tried formatting the URL in different valid ways such as:
- http://www.youtube.com/watch?v=codehere
- https://www.youtube.com/watch?v=codehere
- https://youtu.be/codehere
but I always get a "This video is unavailable" error in the Youtube app. Any version of the link is viewable in a browser. The app was last updated a couple of years ago (and previously worked without any problem), so maybe there is some restriction from Youtube that I'm not aware of?
I'd prefer to keep opening the video via an Intent and URL, and not install any additional library, if possible.
Update!
I attempted to use the YouTubeStandalonePlayer library but I'm getting the same result:
if (isYoutubeVideo) {
final String youtubeApiKey = Prefs.getString(ConfigDumpService.CMS_CONFIG.YOUTUBE_PLAYER_API_KEY);
final String videoId = Strings.extractVideoIdFromUrl(formattedUrl);
context.startActivity(YouTubeStandalonePlayer.createVideoIntent((Activity)context, "my-key-here", videoId));
}
Ty!
Solution
Just for anyone else getting this error, the problem was that somewhere in my code the URL was getting changed to lowercase.
Youtube video IDs are case sensitive, so I was using a non-valid video ID.
Answered By - Sandy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.