Giter Site home page Giter Site logo

ramywagdyrizkalla / mmplayerview Goto Github PK

View Code? Open in Web Editor NEW

This project forked from millmany/mmplayerview

0.0 0.0 0.0 42.06 MB

Custom AVPlayerLayer on view and transition player with good effect like youtube and facebook

License: MIT License

Swift 98.55% Ruby 1.45%

mmplayerview's Introduction

MMPlayerView

paypal

CI Status Version License Platform

Demo

List / Shrink / Transition / Landscape

list shrink transition landscape

MMPlayerLayer

ex. use when change player view frequently like tableView / collectionView
import MMPlayerView
mmPlayerLayer.playView = cell.imgView
mmPlayerLayer.getStatusBlock { [weak self] (status) in

}
self.mmPlayerLayer.set(url: DemoSource.shared.demoData[indexPath.row].play_Url)
self.mmPlayerLayer.resume()

Transition

##PresentedViewController
1. Set transition config
    required init?(coder aDecoder: NSCoder) {
       super.init(coder: aDecoder)
        self.mmPlayerTransition.present.pass { (config) in
            // setting
            .....
        }
    }
2. Set MMPLayerToProtocol on PresentedViewController
3. Set MMPlayerPrsentFromProtocol on PresentingViewController

Shrink

ex. only set present transition can use shrink video
(self.presentationController as? PassViewPresentatinController)?.shrinkView()

Landscape

1.Set MMPlayerLayer
   // roation screen to landscape can change player to fullscreen
   mmplayerLayer.fullScreenWhenLandscape = true
   
2. Set from code
   mmplayerLayer.setOrientation(.landsacpeLeft)
   
3. Observer
  mmPlayerLayer.getOrientationChange { (status) in
        print("Player OrientationChange \(status)")
  }

Cover View

landscape

## add cover item view on player
play.replace(cover: CoverA.instantiateFromNib())

Progress

// Custom your progress view and it will add on player center
// view need to implement ProgressProtocol, and add progress in this view, when start/stop control what need to do
.custom(view: <#T##MMProgressProtocol#>)
 public protocol MMProgressProtocol {
     func start()
     func stop()
 }

Cache

playerLayer.cacheType = .memory(count: 10)
public enum MMPlayerCacheType {
    case none
    case memory(count: Int) // set this to cache seek time in memory and if cache out of count will remove first you    
    stored
}

Layer Protocol

// detect if touch in videoRect
// if touch out of videoRect will not trigger show/hide cover view event
public protocol MMPlayerLayerProtocol: class {

func touchInVideoRect(contain: 

) // 
}

Parameter

public enum MMPlayerCoverAutoHideType {
    case autoHide(after: TimeInterval)
    case disable
}

public enum MMPlayerCacheType {
   case none // set no cache and remove all
   case memory(count: Int) // cache player seek time in memory
}
public enum CoverViewFitType {
  case fitToPlayerView // coverview fit with playerview
  case fitToVideoRect // fit with VideoRect
}
     
public enum ProgressType {
   case `default`
   case none
   case custom(view: ProgressProtocol)
}
public var autoHideCoverType = MMPlayerCoverAutoHideType.autoHide(after: 3.0) // Default hide after 3.0 , set disable to close auto hide cover            
public var progressType: MMPlayerView.ProgressType  
public var coverFitType: MMPlayerView.CoverViewFitType
lazy public var thumbImageView: UIImageView 
public var playView: UIView?
public var coverView: UIView? { get }
public var autoPlay: Bool // when MMPlayerView.MMPlayerPlayStatus == ready auto play video
public var currentPlayStatus: MMPlayerView.MMPlayerPlayStatus 
public var cacheType: MMPlayerCacheType = .none
public var playUrl: URL?
public func showCover(isShow: Bool)
public func setCoverView(enable: Bool)
public func delayHideCover()
public func replace<T: UIView>(cover:T) where T: CoverViewProtocol
public func set(url: URL?, state: ((MMPlayerView.MMPlayerPlayStatus) -> Swift.Void)?)
public func resume() // if loading finish autoPlay = false, need call playerLayer.player.play() where you want
public weak var mmDelegate: MMPlayerLayerProtocol?
public func download(observer status: @escaping ((MMPlayerDownloader.DownloadStatus)->Void)) -> MMPlayerObservation? //Downlaod and observer
public var fullScreenWhenLandscape = true
public private(set) var orientation: OrientationStatus = .protrait
public func setOrientation(_ status: MMPlayerLayer.OrientationStatus)
public func getOrientationChange(status: ((_ status: OrientationStatus) ->Void)?)

Downloader

        var downloadObservation: MMPlayerObservation?

        downloadObservation = MMPlayerDownloader.shared.observe(downloadURL: downloadURL) { [weak self] (status) in
            switch status {
            case .cancelled:
                print("Canceld")
            case .completed:
                DispatchQueue.main.async {
                    self?.downloadBtn.setTitle("Delete", for: .normal)
                    self?.downloadBtn.isHidden = false
                    self?.progress.isHidden = true
                }
            case .downloading(let value):
                self?.downloadBtn.isHidden = true
                self?.progress.isHidden = false
                self?.progress.progress = value
                print("Exporting \(value) \(downloadURL)")
            case .failed(let err):
                DispatchQueue.main.async {
                    self?.downloadBtn.setTitle("Download", for: .normal)
                }
                
                self?.downloadBtn.isHidden = false
                self?.progress.isHidden = true
                print("Download Failed \(err)")
            case .none:
                DispatchQueue.main.async {
                    self?.downloadBtn.setTitle("Download", for: .normal)
                }
                self?.downloadBtn.isHidden = false
                self?.progress.isHidden = true
            case .exist:
                DispatchQueue.main.async {
                    self?.downloadBtn.setTitle("Delete", for: .normal)
                }
                self?.downloadBtn.isHidden = false
                self?.progress.isHidden = true
            }

Delete

        if let info = MMPlayerDownloader.shared.localFileFrom(url: downloadURL)  {
            MMPlayerDownloader.shared.deleteVideo(info)
        }

Requirements

iOS 12.0+
Swift 5.0+

Installation

MMPlayerView is available through CocoaPods. To install it, simply add the following line to your Podfile:

Swift 5 
pod 'MMPlayerView

Author

[email protected]

License

MMPlayerView is available under the MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.