Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first video in a list is not playing #2

Open
sudarvizhi3026 opened this issue Nov 27, 2018 · 7 comments
Open

first video in a list is not playing #2

sudarvizhi3026 opened this issue Nov 27, 2018 · 7 comments

Comments

@sudarvizhi3026
Copy link

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

@khush004
Copy link

Hello @sudarvizhi3026 , Did you get any solution?

@DGP13
Copy link

DGP13 commented Feb 28, 2019

no @sudarvizhi3026

@JolChrSA
Copy link

@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
Copy link

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

@11Shraddha
Copy link

11Shraddha commented Jul 7, 2020

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)
        }
    }
 

@pratikgajbhiye222
Copy link

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

@krishnaprovab
Copy link

try

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

after reloading the tableview / collectionview

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants