How to play videos in uiwebview ios? - ios

I'm building an article reading app for iphone.I'm parsing JSON content of article in uiwebview.
Some of the articles contains videos,But it does not display in the uiwebview.
JSON format for video is
<iframe src=\"\/\/www.youtube.com\/embed\/hdstrm\" height=\"360\" width=\"640\" allowfullscreen=\"\" frameborder=\"0\">
The uiwebview display empty space at the place of video frame
here is screen shot of uiwebview:

Displaying YouTube videos on iOS requires special treatment and is much less straight forward than you would expect (or hope). You can either display the entire YouTube page and let the user take it from there (or try to programmatically simulate a press on the play button), or you can "steal" the MP4 and play it using the media player.
The second option is better because it allows you to control the UI around the video and doesn't force you to display the entire YouTube page. However, it's important to stress that it requires quite a bit of work and is frowned upon by YouTube. In fact, they change the HTML structure of their pages every 2-3 months so that these mechanisms will break, and you won't be able to access the MP4 file directly without changing your code.
For more information on how to access the media file directly and play it, check out https://github.com/larcus94/LBYouTubeView

Related

Embed youtube videos with all the data like youtube website

I'm trying to build website (for my own, and for practice) that coantian youtube videos, I know there is a possibility to embed YouTube videos, but I want to know if there is another way to embed the videos, I want all the information of the video to appear, just like on the YouTube site itself.
I want sonthing like this
Example of a video embedded in a normal way
And that includes the title of the video, its length, upload date (or how long ago), preview of the video (when hovering with the cursor over the video), and I also do not want the YouTube icon to appear in the middle of the video image in any embedded video (before playing it).
I know some things can be done using the YouTube API (like video title / video length information), or using functions (e.g. preview gif) but it's a bit cumbersome, and in any case it does not solve the problem of having the YouTube icon In the center of the image of the video.
So I want to know if there option to enbed youtube video with all the details, or at least if there option the get of the sign of youtube that show in the center of the video.
Sorry for my English if there are any mistakes. Thanks in advance from everyone.

Clickable preview image that auto-loads a Youtube video

We're working on implementing a clickable preview image that will play a Youtube video.
The goal is to avoid loading unnecessary JS code and improve Google Pagespeed score.
We have implemented a solution that works.
But the problem is that it takes two clicks to actually load the Youtube video: one click to display the Youtube video, another to actually start the video.
I know for a fact that it's possible to load start such videos in one click, because solutions such as this one exist (but it requires Wordpress)
How do we approach this? Is there a ready-made solution for implementing lazy loading for videos? (that doesn't require Wordpress?)
I used this small tutorial: https://www.labnol.org/internet/light-youtube-embeds/27941/
You show a thumbnail image of a YouTube video and 'When a visitor clicks the play button, the thumbnail image is replaced with the standard YouTube video player with autoplay set to 1 so it plays the video instantly.'
You need javascript, css and html (no Wordpress). Hope it helps you.

Display youtube video that contains content protected by copyright

I am making a scroll view in which there are multiple instances of UIWebView, each with a youtube video that user can tap and watch. I tried multiple approaches how to this (I mean, what to put in UIWebView), the one that worked best was from https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player
However, I have a video that doesn't play, instead it displays "This video contains content from SME. It is restricted from playback on certain sites" (it worked fine at first and I wasn't getting this message, no idea why it stopped working). Is there a way to make such video play in iOS app? If yes, how?
P.S.
I don't want to kick the user out of my app and send him to youtube app or safari.
I also want to be able to count how many times did user play the video, but this topic is probably big enough for a separate question.
Try loading video with this:
[_videoWebView loadHTMLString:html baseURL:[NSURL URLWithString:#"http://www.youtube.com/"]];

How to play a youtube video list in ios natively

I need to play youtube video lists in an iphone app. I did a quick research but still could not find the answer. Most of the answers out there are about playing a single youtube video in iOS by embedding a youtube url in a HTML page and load it in a UIWebview. But it doesn't seem to be the way for playing a list. But I guess it's possible because there are apps that can do that.
Update: I managed to play a list in a UIWebView with iframe method, but it not what i set out to do. I need to play the video not in a full screen mode. Is there anyway to do so?
Thanks
Using UIWebView's internal MPMoviePlayerController, it may be possible to load the videos one by one by storing their URLs in an array and incrementing the array's object position when the finish event is sent internally by the iFrame's javascript. iFrame methods are documented here, and a way to inject a webview with javascript is shown here.
As for non-inline video playing (only fullscreen), set allowsInlineMediaPlayback to NO on the UIWebView.

Enable navigation of an interactive youtube video embedded on a website

The organization I work for has created an interactive YouTube video in which you can navigate around to other YouTube videos by clicking links within the video - sort of like a choose your own adventure type deal.
Anyway, I was working on a web page that references this video and I'd like to embed the video directly on the page.
The interactive portions actually work while the video is embedded, but unlike how it works when playing on YouTube, the url doesn't actually change and the back button is therefore non-functional.
So if I choose a path and determine that's not where I want to go, the only way to get back would be to reload the entire page and start from the beginning.
I'm guessing my best choice here is to just go ahead and link this off to YouTube, but I wanted to make sure I wasn't missing an obvious easy way to embed this video on the page and keep the back button functionality that's possible when the video plays on YouTube.
Thanks for your time!

Resources