Reputation: 165
I have a weird issue with my embedded youtube video. So I have a webview. I load the URL of the youtube video. When I run the App, everything is fine. The webview loads the video. BUT, when I click on the red play button. Nothing is played. The video won't start. Moreover, when I click on the title of the video. It takes me to the real "Youtube Player" if we can say that. And now if I hit the play button, it starts the video.
When I see tutorials on this everything seems working fine for them. Not for me... NEED HELP ! I am frustrated....
Here is the code part which is handling this :
@IBOutlet var webView: UIWebView!
func initilize()
{
let youtubeURL = "https://www.youtube.com/embed/Q0oIoR9mLwc"
webView.loadHTMLString("<iframe width=\"\(webView.frame.width)\" height=\"\(webView.frame.height)\" src=\"\(youtubeURL)\"?&inline=\"1\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
}
EDIT SOLUTION: Look like Music video from VeVo does that !! Insane !! Wonder Why ?! But as @MohanSingh said It was the URL link. He also made some modification on the inline handling of the video.
@IBOutlet var webView: UIWebView!
func initilize()
{
let youtubeURL = "https://www.youtube.com/embed/JMEEdFz0d7Q"
webView.allowsInlineMediaPlayback = true
let width = webView.frame.width
let height = webView.frame.height
webView.loadHTMLString("<iframe width=\"\(width)\" height=\"\(height)\" src=\"\(youtubeURL)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
}
Regards,
Hary.
Upvotes: 1
Views: 340
Reputation: 7269
try this! webView.allowsInlineMediaPlayback = true
used to playing the video on inline.
@IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
initilize()
}
func initilize()
{
let youtubeURL = "https://www.youtube.com/embed/Q0oIoR9mLwc"
webView.allowsInlineMediaPlayback = true
let width = webView.frame.width
let height = webView.frame.height
webView.loadHTMLString("<iframe width=\"\(width)\" height=\"\(height)\" src=\"\(youtubeURL)?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
}
Upvotes: 1