2016-11-02 13 views
0

私はカスタムを使用cellセル内でビデオを再生する。しかし、それは私に空を示すことですtableViewcell、誰かが私を助けることができますか?テーブルセルでビデオを再生

override func viewDidLoad() { 
    super.viewDidLoad() 

    let Custome = CustomeNavigation(nibName: "CustomeNavigation", bundle: nil) 

    self.view.addSubview(Custome.view) 
    Custome.lbl_customeTitle.text = "FEED" 

    tableView.frame   = CGRect(x:0, y:0, width:view.bounds.width, height:view.bounds.height); 
    tableView.delegate  = self 
    tableView.dataSource = self 

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") 

    self.view.addSubview(tableView) 

} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 2 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
     { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "VedioCell", for: indexPath) as! FeedCell 

    let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") 
    let player = AVPlayer(url: videoURL! as URL) 

    let playerLayer = AVPlayerLayer(player: player) 
    playerLayer.frame = cell.bounds 

    cell.layer.addSublayer(playerLayer) 
    player.play() 

    return cell 
} 
+0

FeedCellクラスを表示できますか? –

答えて

0

import AVKitimport AVFoundationを必ずインポートしてください。

そして、あなたはcellForRowAtIndexPath内部で次のように試すことができます:

let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") 
let player = AVPlayer(url: videoURL! as URL) 

let playerLayer = AVPlayerLayer(player: player) 
playerLayer.frame = (cell?.bounds)! 

cell?.layer.addSublayer(playerLayer) 
cell?.playerView?.layer.addSublayer(playerLayer) 
player.play() 

そして、あなたはまた、あなたがcellForRowAtIndexPathに対処することを確認しました:あなたはswift3を使用している場合

let cell: FeedCell = tableView.dequeueReusableCellWithIdentifier("VedioCell", forIndexPath: indexPath) as! FeedCell 

let videoURL = NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") 
let player = AVPlayer(URL: videoURL!) 

let playerLayer = AVPlayerLayer(player: player) 
playerLayer.frame = cell.bounds 

cell.layer.addSublayer(playerLayer) 
cell?.playerView?.layer.addSublayer(playerLayer) 
player.play() 

return cell 

その後、構文は次のようですあなたがそれらの多くを見せているなら。

+0

ありがとうございます。 Tarvo – Agaram

+0

セル内のボタンをクリックしてビデオを再生したい場合はどうすればいいのですか? – Agaram

+0

うまくいきましたか?ただ、使用: '@IBAction newPostButtonAction FUNC(_差出人:ANYOBJECT){ player.play() }' –