Video Not playing in iOS 10 - ios

In the following code:
// NSURL *videoURL1 = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"]];
NSURL *videoURL2 = [NSURL URLWithString:[NSString stringWithFormat:#"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"]];
AVPlayer *playerV = [AVPlayer playerWithURL:videoURL];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = playerV;
[self presentViewController:playerViewController animated:YES completion:^{
[playerV play];
}];
VideoURL1 is working but videoURL2 is not working and the screen is like this:
I added keys and values in info.plist:

Reason behind not working you second url is that you are whitelisting only "http://www.ebookfrenzy.com" which does not support support secure connection. You should also whitelist "clips.vorwaerts-gmbh.de" in the same manner you have whitelisted "http://www.ebookfrenzy.com" . If you are going to access video from many site dynamically which does not support secure connection(https) then and the below line in your plist.
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
For more detail have a look on following thread-
How do I load an HTTP URL with App Transport Security enabled in iOS 9?

Related

UIWebview showing blank white screen after loading url

Below is the code i have tried:
HTMLBrowserViewController.h
IBOutlet UIWebView * webControl;
HTMLBrowserViewController.m
webControl.scalesPageToFit = YES;
webControl.contentMode = UIViewContentModeScaleAspectFit;
webControl.delegate = self;
NSURL *url1=[NSURL URLWithString:webUrl];
NSURLRequest *requestObject=[NSURLRequest requestWithURL:url1 cachePolicy:NSURLCacheStorageAllowed timeoutInterval:15];
[webControl loadRequest:requestObject];
If you are trying to load an HTTP URL only, please check and enable the AllowArbitaryLoad In the App Transport Security Settings in the info.plist. You can refer to the following link.
Transport security has blocked a cleartext HTTP
If you are using the https URL, please make sure the URL is loading fine in the Safari and as well as in the Chrome browser responsive mode.
Sometimes, the website will load the response URL in iFrame. so please check that pass the correct URL.
Also, print the URL before you pass to the UIWebView, sometimes it should have space and as well as & so remove the same and pass it in the WebView.
serviceBookingUrl = [
NSURLRequest requestWithURL : [
NSURL URLWithString : [
websiteURL stringByReplacingOccurrencesOfString : # "&" withString : # "&"
]
]
];
[PrimaryWebView loadRequest: serviceBookingUrl];
Add NSAppTransportSecurity in your application .plist file
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Check this link transport Security has Blocked a cleartext HTTP
try this :
NSString *encodedString=[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(#"urlString %#",encodedString);
NSURL *url = [NSURL URLWithString:encodedString];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
// Set delegete
webView.delegate=self;
//Load the request in the UIWebView.
[webView loadRequest:requestObj];

MPMoviePlayerController iOS stream m3u8 file not working

im trying to play a m3u8 live streaming file by using this code:
NSURL *movieURL = [NSURL URLWithString:#"http://www.streaming507.com:1935/TVBlast/TVBlast/playlist.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[self.view addSubview:mp.view];
[mp setFullscreen:YES animated:YES];
mp.movieSourceType = MPMovieSourceTypeStreaming;
[mp play];
}
when i copy/paste streaming507.com:1935/TVBlast/TVBlast/playlist.m3u8 in my device in safari browser it plays perfect and it works good how i can fix this?
I dont know what im doing wrong
thank you
i fix the problem by copy/paste this in my info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

Play facebook videos in ios application

I want to embed Facebook videos in my app. I am getting video links from a webservice.
For example:
"video_url": "https://www.facebook.com/urdutimes.ca/videos/520665921438799/"
Is it possible to embed this video in native iOS app using Objective-C?
Thanks in advance
Try this one:
NSURL *url = [NSURL URLWithString:#"https://www.facebook.com/urdutimes.ca/videos/520665921438799/"];
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mp];

AVAssetResourceLoaderDelegate methods not working on device

I have been working on a simple AVPlayer to play encrypted HLS media.
I am using the AVAssetResourceLoaderDelegate to handle the key retrieving process so the encrypted media can be played with a valid key.
The program works perfectly on simulator, but it doesn't work at all on device.
Here are the codes:
- (void) playUrlByAVPlayer:(NSString *) videoUrl
{
NSURL *streamURL = [NSURL URLWithString:videoUrl];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:streamURL options:nil];
[asset.resourceLoader setDelegate:self queue:dispatch_get_main_queue()];
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
[self.playerLayer setFrame:self.view.frame];
[self.view.layer addSublayer:self.playerLayer];
[self.player play];
}
After some debugging, I realized that the delegate method shouldWaitForLoadingOfRequestedResource was never called on device.
I have read other relevant questions:
AVAssetResourceLoaderDelegate not being called
AVAssetResourceLoaderDelegate - Only requests first two bytes?
and I tried enclosing all codes within a dispatch_async, dispatch_get_main_queue block but there's no luck on solving mine.
Currently my codes above are not enclosed by any dispatch queue blocks.
Any thoughts on the problem?
If you take a look on Apple example code where they show bipbop.m3u8 HLS playback you will see that they are using masks for real http requests: "http:/host/bipbop.m3u8" => "custom_scheme:/host/bipbop.m3u8"
Same trick should be made with playlist subresources.
Otherwise avplayer ignores AVAssetResourceLoaderDelegate and load data directly.
You need to implement some kind of mapping:
NSString* videoUrl = #"fake_scheme://host/video.m3u8";
NSURL *streamURL = [NSURL URLWithString:videoUrl];
As I mentioned in the other thread as well, AVAssetResourceLoaderDelegate works only when we use a "Non Standard/Non Reserved" url scheme. HTTP, HTTPS etc are considered reserved URL schemes and iOS will not make a delegate call if the URL has one of those schemes. What I ended up doing was using my_own_http for the http urls and my_own_https for the https urls. It works well after I made that change. As you know this makes your playlist unusable on other deices.
In your delegate shouldWaitForLoadingOfRequestedResource change the URL scheme back to http:
NSURLComponents *urlComponents = [NSURLComponents componentsWithURL:loadingRequest.request.URL resolvingAgainstBaseURL:NO];
urlComponents.scheme = #"http";
NSMutableURLRequest *mutableLoadingRequest = [loadingRequest.request mutableCopy];
[mutableLoadingRequest setURL:urlComponents.URL];
Please find a demo for this working along with a ViewController Implementation
Run this on a Real device only as Simulator doesn't allows https/http on it.
https://github.com/ankit0812/FairplayTestProj

MPMoviePlayerController streaming video not play Audio on iPad

This may be a silly question. But, don't know where the problem actually. I'm trying to stream my http streaming (HLS) through MPMoviePlayercontroller video streaming is fine. But, audio isn't working on real device (Working in Simulator) Here is my code,
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://mydomain:1935/coder/%#/playlist.m3u8", self.streamField.text]];
theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.movieSourceType = MPMovieSourceTypeStreaming;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[theMoviPlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:theMoviPlayer.view];
[theMoviPlayer play];
Has anyone worked on this? I'm getting only with device for audio issue.
Edit
I have tried below one,
NSURL *url = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:player];
This(URL only given to safari) works fine both iPad and Simulator iPad of Safari browser with Audio. But, not working as application on iPad except Simulator.
First add AVFoundation.framework and add below code.
in .h file
#import <AVFoundation/AVFoundation.h>
and .m file
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

Resources