Play YouTube videos in iPhone app without using UIWebView?

前端 未结 5 406
臣服心动
臣服心动 2020-11-29 01:45

I want to play YouTube videos from my iPhone app. I have to tried play YouTube videos in my iPhone app with the following codes,

[self playVideo:@\"http://ww         


        
相关标签:
5条回答
  • 2020-11-29 02:21

    Instead of the HTML embed code you are using, go to the YouTube website, find a video, use the share button and then the Embed button to get some example Embed HTML. Use that pattern for embedding the video rather than the Flash version you are currently using.

    0 讨论(0)
  • 2020-11-29 02:25

    Mr.Yuvaraj.M your above code is correct. Please run the project in your iPhone/iPod touch device. The youtube videos may not support/not work in Simulator. Please check on this. Thanks.

    0 讨论(0)
  • 2020-11-29 02:28

    There is now a YTPlayerView class available with the YouTube Data API (v3).

    Have a look at Using the YouTube Helper Library to embed YouTube videos in your iOS application

    It gives comprehensive instructions on how to install the helper library, and incorporate YTPlayerView into your storyboard.

    0 讨论(0)
  • 2020-11-29 02:33

    Play youtube video in swift 4.1

    Add Pod pod 'XCDYouTubeKit'

    import XCDYouTubeKit in ViewController

    func playYoutubeVideo(){
    
    let strUrl = "https://www.youtube.com/watch?v=9m_K2Yg7wGQ"
    if let range = strUrl.range(of: "=") {
            let strIdentifier = strUrl.substring(from: range.upperBound)
            print("Identifier:\(strIdentifier)")
            let videoPlayerViewController = 
            XCDYouTubeVideoPlayerViewController(videoIdentifier: strIdentifier)
            videoPlayerViewController.present(in: viewYTVideo)
            videoPlayerViewController.moviePlayer.play()
        }
    }
    
    0 讨论(0)
  • 2020-11-29 02:41

    Just use XCDYouTubeVideoPlayerViewController. It seamlessly adds youtube video to your app without the need of UIWebView.

    It uses progressive download + MoviePlayer and AVFoundation frameworks. Just supply it with a youtube video ID and you are good to go.

    It supports both full-screen & non full-screen and WORKS ON iOS SIMULATOR!!!

    Example:

    XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
    [self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];
    
    0 讨论(0)
提交回复
热议问题