AutoVideoPlayer icon indicating copy to clipboard operation
AutoVideoPlayer copied to clipboard

first video in a list is not playing

Open sudarvizhi3026 opened this issue 7 years ago • 7 comments

Hi any one help first video in a tableview is not playing only sound is coming please provide me update on this issue

sudarvizhi3026 avatar Nov 27 '18 10:11 sudarvizhi3026

Hello @sudarvizhi3026 , Did you get any solution?

khush004 avatar Feb 27 '19 10:02 khush004

no @sudarvizhi3026

DGP13 avatar Feb 28 '19 06:02 DGP13

@ashish0309 Can you give a solution for Video in the First cell is not playing when it appears the first time, we have to drag its bottom slightly to play the video.

Plz, help me with that. Thanks in advance.

JolChrSA avatar Jun 12 '20 06:06 JolChrSA

I got one solution for that, Put pausePlayeVideos() method in Api call after reload table view. This works for me.

JolChrSA avatar Jun 12 '20 08:06 JolChrSA

I solved it with this. There is an issue with your current and fully visible item of collectionview.

Add this method in ASVideoPlayerController above pausePlayeVideosFor.

func fullyVisibleCells(_ inCollectionView: UICollectionView) -> [UICollectionViewCell] {

        var returnCells = [UICollectionViewCell]()

        var vCells = inCollectionView.visibleCells
        vCells = vCells.filter({ cell -> Bool in
            let cellRect = inCollectionView.convert(cell.frame, to: inCollectionView.superview)
            return inCollectionView.frame.contains(cellRect)
        })
        vCells.forEach({
            returnCells.append($0)
        })
        return returnCells
    }

Replace pausePlayeVideosFor to this

       func pausePlayeVideosFor(collectionView: UICollectionView, appEnteredFromBackground: Bool = false) {
        let visisbleCells = fullyVisibleCells(collectionView)
        var videoCellContainer: ASAutoPlayVideoLayerContainer?
        var maxHeight: CGFloat = 0.0
       
        for cellView in collectionView.visibleCells {
            guard let containerCell = cellView as? ASAutoPlayVideoLayerContainer,
                let videoCellURL = containerCell.videoURL else {
                    continue
            }
            let height = containerCell.visibleVideoHeight()
            if maxHeight < height {
                maxHeight = height
                videoCellContainer = containerCell
            }
            pauseRemoveLayer(layer: containerCell.videoLayer, url: videoCellURL, layerHeight: height)
        }
        
        guard let videoCell = visisbleCells.first as? ASAutoPlayVideoLayerContainer,
            let videoCellURL = videoCell.videoURL else {
                return
        }
        
        
        let minCellLayerHeight = videoCell.videoLayer.bounds.size.height * 0.5
        /**
         Visible video layer height should be at least more than max of predefined minimum height and
         cell's videolayer's 50% height to play video.
         */
        let minimumVideoLayerVisibleHeight = max(minCellLayerHeight, minimumLayerHeightToPlay)
        if maxHeight > minimumVideoLayerVisibleHeight {
            if appEnteredFromBackground {
                setupVideoFor(url: videoCellURL)
            }
            playVideo(withLayer: videoCell.videoLayer, url: videoCellURL)
        }
    }
 

11Shraddha avatar Jul 07 '20 11:07 11Shraddha

I solved it with this. There is an issue with your current and fully visible item of collectionview.

Add this method in ASVideoPlayerController above pausePlayeVideosFor.

func fullyVisibleCells(_ inCollectionView: UICollectionView) -> [UICollectionViewCell] {

        var returnCells = [UICollectionViewCell]()

        var vCells = inCollectionView.visibleCells
        vCells = vCells.filter({ cell -> Bool in
            let cellRect = inCollectionView.convert(cell.frame, to: inCollectionView.superview)
            return inCollectionView.frame.contains(cellRect)
        })
        vCells.forEach({
            returnCells.append($0)
        })
        return returnCells
    }

Replace pausePlayeVideosFor to this

       func pausePlayeVideosFor(collectionView: UICollectionView, appEnteredFromBackground: Bool = false) {
        let visisbleCells = fullyVisibleCells(collectionView)
        var videoCellContainer: ASAutoPlayVideoLayerContainer?
        var maxHeight: CGFloat = 0.0
       
        for cellView in collectionView.visibleCells {
            guard let containerCell = cellView as? ASAutoPlayVideoLayerContainer,
                let videoCellURL = containerCell.videoURL else {
                    continue
            }
            let height = containerCell.visibleVideoHeight()
            if maxHeight < height {
                maxHeight = height
                videoCellContainer = containerCell
            }
            pauseRemoveLayer(layer: containerCell.videoLayer, url: videoCellURL, layerHeight: height)
        }
        
        guard let videoCell = visisbleCells.first as? ASAutoPlayVideoLayerContainer,
            let videoCellURL = videoCell.videoURL else {
                return
        }
        
        
        let minCellLayerHeight = videoCell.videoLayer.bounds.size.height * 0.5
        /**
         Visible video layer height should be at least more than max of predefined minimum height and
         cell's videolayer's 50% height to play video.
         */
        let minimumVideoLayerVisibleHeight = max(minCellLayerHeight, minimumLayerHeightToPlay)
        if maxHeight > minimumVideoLayerVisibleHeight {
            if appEnteredFromBackground {
                setupVideoFor(url: videoCellURL)
            }
            playVideo(withLayer: videoCell.videoLayer, url: videoCellURL)
        }
    }
 

Can You help to achieve my collection view with auto video support

pratikgajbhiye222 avatar Jul 20 '20 15:07 pratikgajbhiye222

try

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) {
                                    self.pausePlayeVideos()
                                }

after reloading the tableview / collectionview

krishnaprovab avatar Oct 28 '20 17:10 krishnaprovab