All Projects → ashish0309 → AutoVideoPlayer

ashish0309 / AutoVideoPlayer

Licence: MIT license
Easily Play/Pause videos in any UIView subclass especially UITableViewCell subclass

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to AutoVideoPlayer

AVPlayerItemHomeOutput
Coordinate the output of content associated with your HomeKit lightbulbs. #Ambilight
Stars: ✭ 38 (-56.82%)
Mutual labels:  avfoundation, avplayer, avplayeritem
Sjvideoplayer
iOS VideoPlayer MediaPlayer video player media player 短视频播放器 可接入 ijkplayer aliplayer alivodplayer plplayer
Stars: ✭ 2,066 (+2247.73%)
Mutual labels:  avplayer, videoplayer
Videoplayer
📽 A video player for SwiftUI, support for caching, preload and custom control view. SwiftUI 视频播放器,支持边下边播、预加载、自定义控制层
Stars: ✭ 212 (+140.91%)
Mutual labels:  avplayer, videoplayer
MBVideoPlayer
A video player on top of AVQueuePlayer with custom header, playlist items, play, pause, seek to slider, time, resize to fullscreen, forward, backward horizontal, vertical capabilities.
Stars: ✭ 103 (+17.05%)
Mutual labels:  avplayer, videoplayer
iphonepip
PiP (Picture in Picture) prototype for iPhone
Stars: ✭ 15 (-82.95%)
Mutual labels:  avfoundation, avplayer
Arplayer
Playback videos using ARKit and AVFoundation.
Stars: ✭ 117 (+32.95%)
Mutual labels:  avfoundation, avplayer
Sbplayer ios
基于AVPlayer封装的轻量级播放器,可播放本地及网络视频,易于定制
Stars: ✭ 134 (+52.27%)
Mutual labels:  avfoundation, avplayer
TravellingApp
Xamarin.Forms goodlooking UI sample using the new CarouselView.
Stars: ✭ 52 (-40.91%)
Mutual labels:  videoplayer
oscp-omnibus
A collection of resources I'm using while working toward the OSCP
Stars: ✭ 46 (-47.73%)
Mutual labels:  videos
Jetpack Kotlin Eyepetizer
一款基于Kotlin + Jetpack核心组件 + 协程 + 组件化实现的精美仿开眼视频App(提供Flutter、React Native、小程序版本 😁 )
Stars: ✭ 82 (-6.82%)
Mutual labels:  videoplayer
GQImageVideoViewer
仿微信多图片及视频浏览器,图片和视频原尺寸显示,不会变形,双击图片放大缩小,单击消失,支持多张本地和网络图片以及网络视频混合查看,支持链式调用
Stars: ✭ 57 (-35.23%)
Mutual labels:  avplayer
clappr-vast-ad-plugin
Plugin for playing advertisements by VAST protocol
Stars: ✭ 14 (-84.09%)
Mutual labels:  videoplayer
nzsl-online
New Zealand Sign Language Dictionary
Stars: ✭ 30 (-65.91%)
Mutual labels:  videos
DPVideoMerger
Multiple videos merge in one video with manage scale & aspect ratio and also merge 4 videos to grid layou for Objective C.
Stars: ✭ 12 (-86.36%)
Mutual labels:  videos
Starling
Simple low-latency audio library for iOS + macOS
Stars: ✭ 38 (-56.82%)
Mutual labels:  avfoundation
TwitchPotPlayer
Extensions for PotPlayer to watch Twitch streams without streamlinks or any crap.
Stars: ✭ 159 (+80.68%)
Mutual labels:  videoplayer
OneDrive-Cloud-Player
OneDrive Cloud Player is a media player dedicated for streaming files directly from OneDrive.
Stars: ✭ 28 (-68.18%)
Mutual labels:  videoplayer
Lassi-Android
All in 1 picker library for android.
Stars: ✭ 108 (+22.73%)
Mutual labels:  videos
DPVideoMerger-Swift
Multiple videos merge in one video with manage scale & aspect ratio and also merge videos to grid matrix layout for Swift.
Stars: ✭ 49 (-44.32%)
Mutual labels:  videos
vivict
An easy to use in-browser tool for subjective comparison of the visual quality of different encodings of the same video source.
Stars: ✭ 62 (-29.55%)
Mutual labels:  videostreaming

AutoVideoPlayer

Play/pause videos automatically in UITableview when an UITableViewCell is in focus, videos can be easily embedded in any UITableViewCell subclass. Can be easily extended to support UICollectionView

  • Easily implement video player in any UITableView subclass
  • Automatic video play when video view is visible and option to easily pause/play any video
  • Mute/Unmute videos
  • Videos are cached in memory and will be removed when there is memory pressure
  • The scroll of UITableView is super smooth since video assets are downloaded on background thread and played only when assets are completely downloaded ensuring the main thead is never blocked
  • Option to provide different bit rate for videos
  • Works when the app comes again from background

It can also be used to play videos in any subclass of UIView.

Demo

Download

Drag and drop the VideoPlayLibrary folder in your project

Usage

Adopt ASAutoPlayVideoLayerContainer protocol in your UITableviewCell subclass like below.

var videoLayer: AVPlayerLayer = AVPlayerLayer()
    
var videoURL: String? {
    didSet {
        if let videoURL = videoURL {
            ASVideoPlayerController.sharedVideoPlayer.setupVideoFor(url: videoURL)
        }
        videoLayer.isHidden = videoURL == nil
    }
}

Implement following method to return the visible height of the UITableViewCell

func visibleVideoHeight() -> CGFloat {
  //return visible height of the Video Player layer
}

ViewController Code

Put following code in viewDidLoad

NotificationCenter.default.addObserver(self,
                                       selector: #selector(self.appEnteredFromBackground),
                                       name: NSNotification.Name.UIApplicationWillEnterForeground, object: nil)

Add following code to play/pause when view appears/disappears

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    pausePlayeVideos()
}

Add following methods

@objc func appEnteredFromBackground() {
    ASVideoPlayerController.sharedVideoPlayer.pausePlayeVideosFor(tableView: tableView, appEnteredFromBackground: true)
}

func pausePlayeVideos(){
    ASVideoPlayerController.sharedVideoPlayer.pausePlayeVideosFor(tableView: tableView)
}

Add following code in UITableView delegate and datasource methods

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    //if cell adopts ASAutoPlayVideoLayerContainer protocol then
    //set videoURL if you want to show video or else nil
}

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    if let videoCell = cell as? ASAutoPlayVideoLayerContainer, videoCell.videoURL != nil {
        ASVideoPlayerController.sharedVideoPlayer.removeLayerFor(cell: videoCell)
    }
}

Add following code to pause/play videos when scroll stops

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
    if !decelerate {
        pausePlayeVideos()
    }
}
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    pausePlayeVideos()
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].