container view を使って上を動画ビュー。
下を動画を選択するnavigationを用いたtableviewで実装しています。
SongTVC(下のtableviewcon)からVideoviewCon(上のviewcon)を制御するために
SongVCTで
// Cell が選択された場合 override func tableView(_ table: UITableView,didSelectRowAt indexPath: IndexPath) { self.appDelegate.selectMV = self.appDelegate.videoIDAR[indexPath.row] let video = ViewController() let vars = ["playsinline": 1, "controls": 2, "showinfo": 0, "origin":"https://www.google.com"] as [String : Any] video.playerView!.load(withVideoId: self.appDelegate.selectMV, playerVars: vars) video.playerView!.playVideo() }
と実装したのですが
となり、playerView(YTPlayerView!)がnilでfatal error: unexpectedly found nil while unwrapping an Optional value
(lldb) となっていました。
どうすれば正しく取得できるのでしょうか?
追記
動画viewコード
import UIKit import youtube_ios_player_helper import AVFoundation class ViewController: UIViewController, YTPlayerViewDelegate{ @IBOutlet var playerView: YTPlayerView! var appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate override func viewDidLoad() { super.viewDidLoad() ///self.playerView?.delegate = self self.playerView.delegate = self //self.playerView?.sizeToFit() self.playerView.sizeToFit() player() let audioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(AVAudioSessionCategoryPlayback) } catch { print("") } } func playerViewDidBecomeReady(_ playerView: YTPlayerView) { playerView.playVideo() } func play() { print("Push! play") //playerView.stopVideo() //playerView.delegate = self //self.playerView = YTPlayerView() playerView.load(withVideoId: self.appDelegate.selectMV) playerView.playVideo() } func player(){ let vars = ["playsinline": 1, "controls": 2, "showinfo": 0, "origin":"https://www.google.com"] as [String : Any] if self.appDelegate.selectMV == "" { print("Not load",self.appDelegate.selectMV) } else { print("Loaded",self.appDelegate.selectMV) playerView.load(withVideoId: self.appDelegate.selectMV, playerVars: vars) print("Check this",playerView) } } }
IBOutletで宣言したものを画像のように紐付けています
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/28 00:44
2016/09/28 00:52
2016/09/28 00:57
2016/09/28 01:08
2016/09/28 01:18
2016/09/28 02:02
2016/09/28 02:12
2016/09/28 02:33
2016/09/28 02:41
2016/09/28 03:04
2016/09/28 03:36
2016/09/28 05:51