So, I’m using two different methods of playing a twitch stream in an iOS UIWebView, one of which works, but offers me no control, and the other method does not work, but would offer me the control I’m looking for.
The first method is just making the web view load the page from the URL, see below.
NSURL *streamURL = [NSURL URLWithString:@"http://www.twitch.tv/giantwaffle/hls"]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:streamURL]; [_webView loadRequest:urlRequest];
Now this method works, it displays a player in the UIWebView, a “play” button appears that allows the stream to start, and you can watch the live stream. Using this method though, I have no control over the parameters of the video player, such as whether or not it displays the controls, or if it autoplays.
The secondary method, which I would like to use, is to create an html file, and load it in to the UIWebView, like below.
NSURL *url = [[NSBundle mainBundle] URLForResource:@"EmbeddedPlayer" withExtension:@"html"]; NSString *htmlString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil]; NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [_webView loadHTMLString:htmlString baseURL:baseUrl];
In the above example I have a file in my project called “EmbeddedPlayer.html” that is just the source returned from a twitch stream’s “/hls” address. When I load this into the UIWebView though, it won’t allow me to begin streaming. It shows the thumbnail from the stream just fine, similar to what the previous method would, but there’s no play button that appears, and I can’t find a way to start the stream.
I don’t understand why there inconsistencies between these two methods, as far as I can understand they should be working the same. Anyone have any idea why they’re behaving differently? Is there a way I can access the video player’s attributes and still have some that functions?