2016-07-30 3 views
0

「performSegueWithIdentifier」がボタンから呼び出されるように設定されています。動画のURLは 'self.specimen.filmMovieLink'という文字列です。このフィールドをAVControllerにどのように渡すのですか?私は 'newMovie'と呼ばれるセグを設定して、AV View Controllerシーンをストーリーボードに追加しました(そのシーンをコントロールするためのコードや添付ファイルはありません)。「performSegueWithIdentifier」ボタンからAVPlayerコントローラにビデオフィールドを渡す方法2.2

私はperformSegueWithIdentifierからそれを通じ送信する必要があります(「NewMovie」、送信者:specimenAnnotation)

私はURLとそれがAVPlayerコントローラーを開きますが、ビデオを再生しない作業URLと直接文字列を追加する場合は、私はこのコードをしようとしたとき:
performSegueWithIdentifier( "watchMovie"、送信者:specimenAnnotation) のlet URL = NSURL(文字列: "https://www.example.com/video.mp4")

このコードは、から私のフィールドでAVControllerに動画のURLをセグエに取り組んでいます「prepareForSegue」を代わりに使用する別のView Controller:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
     let destination = segue.destinationViewController as! 
     AVPlayerViewController 
     let url = NSURL(string: self.specimen.filmMovieLink) 
     destination.player = AVPlayer(URL: url!) 

    } 
} 

私は 'performSegueWithIdentifier'に適応しようとしましたが、初心者であり、動作させることができませんでした。私のフィールド(self.specimen.filmMovieLink)を、この 'prepareForSegue'の代わりに 'performSegueWithIdentifier'を使ってAVコントローラに渡すには、そのコード(または新しいコードが必要なもの)をどのように適応させることができますか?あなたのviewDidLoadで

// create a property observer that is set to nil then would change until something was assigned it to 
var myURL:URL? = nil { 
    willSet(newValue) { 
     print("newvalue \(newValue)") 
    } 
    didSet{ 
    // could do more stuff if needed it 
    } 
} 

いずれか、またはあなたのUIButtonのアクションメソッドの内部で、あなたはその後

 myURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") 

以下の行を呼び出すことができます。

答えて

1

私はそれに近づくような方法、私は、プロパティのオブザーバーを作成します

@IBAction func MyButton(sender:UIButton) { 
     performSegue(withIdentifier: "segueIdentifier", sender: nil) 
} 

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) { 
    let destination = segue.destinationViewController as! AVPlayerViewController 
    guard let _url = myURL else {return } 
    destination.player = AVPlayer(url: _url) 
    destination.player?.play() 
} 

ヴォイラ、テーブルビューを使用したい場合は、チェックアウト可能 my github project

+0

Lamarに感謝します。私はそれを試します。 MineはUIButtonではありませんが、ボタンのようにタップしたコールアウトなので、私はまだ動作するはずです。コード:func mapView(mapView:MKMapView、annotationView:MKAnnotationView、calloutAccessoryControlTappedコントロール:UIControl){ if specimenAnnotation = annotationView.annotation as? SpecimenAnnotation {そして、上記のように 'performSegue'。私はあなたが示唆したコードをどこに正確に追加するのか少し分かりません。 –

+0

私はあなたが 'UIButton'をよく使っているのを見たと思っていました。それはどうすればいいのか教えてください。 – Lamar

+0

PSあなたのgithubプロジェクトについてのヒントをくれてありがとう、間違いなく私のプロジェクトに統合するのは大変です。 –

関連する問題