【问题标题】:MP4 video on playing in xamarin.ios在 xamarin.ios 中播放的 MP4 视频
【发布时间】:2018-01-23 13:10:16
【问题描述】:

我正在使用代码:视频没有播放

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 将在此 URL 播放此视频: http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8 但不是这个: http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4

【问题讨论】:

    标签: xamarin xamarin.ios


    【解决方案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);
    

    如果这不起作用,那么我会问另一个问题,以便其他人可以看到它。

    【讨论】:

    • @lain 我们可以在视频没有开始播放之前显示加载器吗??
    • 我看到你刚刚加入了stackoverflow,所以通常我们应该在每个帖子中保留一个问题,你应该问另一个问题,例如“使用 MPMoviePlayerController 时如何显示加载屏幕?”可以在这里找到原因meta.stackexchange.com/q/222735/342918 在Objective-C 中还有其他类似的问题。 stackoverflow.com/q/4877739/1107580 使用 MPMoviePlayerViewController 而不是 MPMoviePlayerController 的状态可以显示加载屏幕。我将更新我的答案,向您展示如何使用它。
    • 另外请将@IainSmith 的答案标记为解决方案,以便问题得到解决:-)。
    • 感谢您的回复,但 MPMoviePlayerViewController 已被弃用,这就是我使用 MPMoviePlayerController 的原因
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-06
    • 2011-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-23
    相关资源
    最近更新 更多