【问题标题】:How to play youtube videos in Xamarin.iOS app如何在 Xamarin.iOS 应用中播放 youtube 视频
【发布时间】:2018-01-31 08:19:31
【问题描述】:

我正在使用代码:

moviePlayer = new MPMoviePlayerController(new NSUrl("https://www.youtube.com/watch?v=9SdF_1OrN0Y"));

moviePlayer.View.Frame = new RectangleF(10, 80, 300, 200);
            moviePlayer.View.BackgroundColor = UIColor.Clear;
            moviePlayer.SourceType = MPMovieSourceType.File;
            //moviePlayer.SetFullscreen(true,true);
            moviePlayer.Fullscreen = true;
            // 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);

添加代码后

<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>

我可以使用以下网址播放视频: http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4

如何播放来自 API 响应的 YouTube 视频?

[
    {
        "VideoId": 1,
        "VideoTitle": "Selena Gomez testimony hillsong conference 2017",
        "VideoUrl": "https://www.youtube.com/watch?v=9SdF_1OrN0Y"
    }
]

【问题讨论】:

标签: ios xamarin xamarin.ios


【解决方案1】:

如果您无法播放 youtube url,那么您应该使用该视频的嵌入 url 而不是 youtube url 普通 youtube 网址:https://www.youtube.com/watch?v=9SdF_1OrN0Y 嵌入 youtube 网址:https://www.youtube.com/embed/9SdF_1OrN0Y

如果您不知道如何将 youtube 普通网址转换为嵌入网址,请参考此网址Convert youtube url to iframe embed code

如果有任何疑问,请告诉我 快乐编码:)

【讨论】:

  • 感谢您的回复。我正在寻找 C# 中的示例代码,如 URL 中的第二个解决方案:stackoverflow.com/questions/1779511/…
  • 给我你的解决方案我会修改它我会发给你
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-19
  • 2014-05-01
  • 2012-07-18
  • 2012-10-17
  • 1970-01-01
  • 2018-08-06
相关资源
最近更新 更多