我正在使用代码:视频无法播放
moviePlayer = new MPMoviePlayerController(new NSUrl("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
//set appearance of video player
moviePlayer.View.Frame = new RectangleF(10, 80, 300, 200);
moviePlayer.View.BackgroundColor = UIColor.Clear;
moviePlayer.SourceType = MPMovieSourceType.File;
// Set this property True if you want the video to be auto played on page load
moviePlayer.ShouldAutoplay = true;
// If you want to keep the Video player on-ready-to-play state, then enable this
// This will keep the video content loaded from the URL, untill you play it.
moviePlayer.PrepareToPlay();
// Enable the embeded video controls of the Video Player, this has several types of Embedded controls for you to choose
moviePlayer.ControlStyle = MPMovieControlStyle.Default;
View.AddSubview(moviePlayer.View);
moviePlayer
将在此网址上播放此视频:
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
但不是这个:
http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4
答案 0 :(得分:1)
我运行了你的代码并得到了这个错误:
传输安全性阻止了明文HTTP(http://)资源加载,因为它不安全。可以通过应用程序的Info.plist文件配置临时例外。
所以我在Info.plist中添加了这个例外 :
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>clips.vorwaerts-gmbh.de</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
想想当你去发布你的应用程序时,你应该针对所有链接使用https。
<强>更新强> 使用MPMoviePlayerViewController
var moviePlayer = new MPMoviePlayerViewController(new NSUrl("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
//set appearance of video player
moviePlayer.View.Frame = new RectangleF(10, 80, 300, 200);
moviePlayer.View.BackgroundColor = UIColor.Blue;
moviePlayer.MoviePlayer.SourceType = MPMovieSourceType.File;
// Set this property True if you want the video to be auto played on page load
moviePlayer.MoviePlayer.ShouldAutoplay = true;
// If you want to keep the Video player on-ready-to-play state, then enable this
// This will keep the video content loaded from the URL, untill you play it.
moviePlayer.MoviePlayer.PrepareToPlay();
// Enable the embeded video controls of the Video Player, this has several types of Embedded controls for you to choose
moviePlayer.MoviePlayer.ControlStyle = MPMovieControlStyle.Default;
View.AddSubview(moviePlayer.View);
如果这不起作用,那么我会问另一个问题,以便其他人可以看到它。