如何将 Youtube 视频嵌入到我的应用程序中? [英] How to embed a Youtube video into my app?
问题描述
我正在尝试为我的 Swift 应用程序创建一个视频播放器,但我不断收到未解析标识符 AVPlayerViewController"的错误消息.我错过了什么?
I'm trying to create a video player for my Swift app, but I keep getting the error of 'unresolved identifier AVPlayerViewController'. What am I missing?
我是这方面的初学者,我可能不得不用外行的话问几千次.我已经在互联网上搜索了一天,以获取有关如何将 Youtube 视频嵌入到我的应用程序中的视频,但没有结果.如果你能给我指点一个很棒的教程!
I'm a beginner at this, I may have to ask a few thousand times in layman's terms. I've been scouring the internet for perhaps a day now for a video for how to embed a Youtube video into my app, with no results. If you could point me over to a tutorial that would be awesome!
谢谢!
推荐答案
Xcode 8.2 • Swift 3.0.2
Xcode 8.2 • Swift 3.0.2
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var wv: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
loadYoutube(videoID: "oCm_lnoVf08")
}
func loadYoutube(videoID:String) {
guard
let youtubeURL = URL(string: "https://www.youtube.com/embed/(videoID)")
else { return }
wv.loadRequest( URLRequest(url: youtubeURL) )
}
}
<小时>
Xcode 7.3.1 • Swift 2.x
Xcode 7.3.1 • Swift 2.x
import UIKit
class ViewController: UIViewController {
// create an outlet for your webview
@IBOutlet weak var wv: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// load your you tube video ID
loadYoutube(videoID: "oCm_lnoVf08")
}
func loadYoutube(videoID videoID:String) {
// create a custom youtubeURL with the video ID
guard
let youtubeURL = NSURL(string: "https://www.youtube.com/embed/(videoID)")
else { return }
// load your web request
wv.loadRequest( NSURLRequest(URL: youtubeURL) )
}
}
这篇关于如何将 Youtube 视频嵌入到我的应用程序中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!