我有一個非常基本的/簡單的swift應用程序,嵌入WebView通過URL鏈接到Youtube視頻。請參閱下面的完整代碼。我想添加10個其他Youtube URL,並通過一個名爲「shuffleButton」的按鈕在WebView中隨機填充它們。我怎麼能夠非常簡單地使用這個按鈕來加載視頻,然後隨機隨機播放它們。我可以在同一個ViewController中找到視頻URL的主列表嗎?謝謝!隨機隨機清單的URL - 斯威夫特
// ViewController.swift
@IBOutlet var videoView: UIWebView!
@IBOutlet var shuffleButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let youtubeURL = "https://www.youtube.com/embed/Rg6GLVUnnpM"
videoView.allowsInlineMediaPlayback = true
videoView.loadHTMLString("<iframe width=\"\(videoView.frame.width)\" height=\"\(videoView.frame.height)\" src=\"\(youtubeURL)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}