2017-03-15 4 views
-1

私はそのビデオ映像は、ローカルディレクトリプレイ動画

からダウンロードして再生する場合、単一のセルにコレクションビューセルでビデオを再生して

セルは、ビデオと画像の両方を持つことができ、問題を持っています

ビューは各行の2つのセル

問題がある持っているコレクション:私は、私は、セルに次のコードを使用したビデオは、一度に1セルでプレーしたいと、そのビデオはもう見え

されていないときに停止をインデックスパスの項目。

let localVideoURL = getDownloadedVideoPathFromDocumentDirectory(filename: eachTimeLineFeed.mediaFile!) 
    print("Play Video from URL \(localVideoURL)") 

     let item = AVPlayerItem(url: localVideoURL!); 
     self.avPlayer = AVPlayer(playerItem: item); 
     self.avPlayer?.actionAtItemEnd = .none 
     self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer); 

     self.avPlayerLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill 
     self.avPlayerLayer?.frame = CGRect(x: 0, y: 0, width: SCREENWIDTH()/2, height: SCREENWIDTH()/2) 
     cell.viewVideo.layer.addSublayer(self.avPlayerLayer!) 
     NotificationCenter.default.addObserver(self, selector: #selector(self.playerItemDidReachEnd), name: NOTIFICATION_PLAYER_DID_END_PLAYING_VIDEO, object: self.avPlayer?.currentItem!) 
     self.avPlayer?.play() 
+0

あなたは上記の質問を持っている何の問題? – Shubhank

+0

現在直面している問題は何ですか? – sourav

+0

表示され、すべての動画があるセルはすべて再生され、動画をスクロールしても停止しません。 – Khushboo

答えて

2

あなたのViewController collectionView:didEndDisplayingCell:forItemAtIndexPath:にcollectionviewオプションのデリゲートを追加し、この関数の内部で、あなたはindexpath、セル、コレクションビューに到達することができます。次に、セル項目のビデオの再生を停止することができます。

スウィフト

func collectionView(_ collectionView: UICollectionView, 
        didEndDisplaying cell: UICollectionViewCell, 
        forItemAt indexPath: IndexPath) { 

} 

のObjective-C

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath { 

}