Versatile Video Player implementation for iOS, macOS, and tvOS

Overview

CI Status Version License Platform

News

๐ŸŽ‰ - Since 2.1.3 VersaPlayer now supports iOS, macOS, and tvOS

Community

If you have any doubts or need help with anything, head over to Gitter and ask it there!

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

IMPORTANT: If you do not have an Apple ID with a developer account for code signing apps, the build will fail with a code signing error. To work around this, you can delete the "Code Signing Identity" build setting of the "Application" target to work around the issue.

Alternatively, if you do have a developer account, you can create the file "Examples/Xcode-config/DEVELOPMENT_TEAM.xcconfig" with the following build setting as its content:

DEVELOPMENT_TEAM = [Your TeamID]

For a more detailed description of this, you can have a look at the comments at the end of the file "Examples/Xcode-config/Base.xcconfig".

Installation

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

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

pod 'VersaPlayer'

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. To integrate Alamofire into your Xcode project using Carthage, specify it in your Cartfile:

github "josejuanqm/VersaPlayer" "3.0.0"

Usage

Basic Usage

VersaPlayer aims to be simple to use but also flexible, to start using VersaPlayer first create a view programatically or via storyboard. Then add this few lines of code to start playing your video.

    @IBOutlet weak var playerView: VersaPlayerView!

    override func viewDidLoad() {
        super.viewDidLoad()
        if let url = URL.init(string: "http://rmcdn.2mdn.net/Demo/html5/output.mp4") {
            let item = VersaPlayerItem(url: url)
            playerView.set(item: item)
        }
    }

Adding Controls

To add controls for your player use the VersaPlayerControls class, which comes packed with outlets to control your player, you can also add as many as you like by making a custom implementation.

VersaPlayerControls class include the following outlets:

Outlet Name Type Action
playPauseButton VersaStatefullButton Toggle playback
fullscreenButton VersaStatefullButton Toggle fullscreen mode
pipButton VersaStatefullButton Toggle PIP mode in supported devices
rewindButton VersaStatefullButton Rewind playback
forwardButton VersaStatefullButton Fast forward playback
skipForwardButton VersaStatefullButton Skip forward the time specified in second at skipSize (found in VersaPlayerControls)
skipBackwardButton VersaStatefullButton Skip backward the time specified in second at skipSize (found in VersaPlayerControls)
seekbarSlider VersaSeekbarSlider Seek through playback
currentTimeLabel VersaTimeLabel Indicate the current time
totalTimeLabel VersaTimeLabel Indicate the total time
bufferingView UIView Shown when player is buffering
    @IBOutlet weak var playerView: VersaPlayerView!
    @IBOutlet weak var controls: VersaPlayerControls!

    override func viewDidLoad() {
        super.viewDidLoad()
        playerView.use(controls: controls)
        if let url = URL.init(string: "http://rmcdn.2mdn.net/Demo/html5/output.mp4") {
            let item = VersaPlayerItem(url: url)
            playerView.set(item: item)
        }
    }

Advanced Usage

DRM

VersaPlayer also brings support for encrypted content, to make use of this functionality you must implement VersaPlayerDecryptionDelegate and assign it to VersaPlayer's decryptionDelegate property.

To read more about this topic go to:

https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/Protocols/VersaPlayerDecryptionDelegate.html

Tracks

To make use of different media tracks, such as audio, video, or captioning, use VersaPlayerMediaTracks, found in VersaPlayer class.

to learn more about this properties go to:

https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/Classes/VersaPlayerMediaTrack.html

Audio Tracks

Audio tracks are specially helpfull when dealing with different languages, for example for a movie playback.

To select an audio track simply fetch available tracks with VersaPlayer's audioTracks property.

    @IBOutlet weak var playerView: VersaPlayer!

    ...
    
    let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.audioTracks
    /// the name of the track
    let name = tracks.first?.name
    /// the language of the track
    let name = tracks.first?.language
    /// selecting the first one
    tracks.first?.select(for: playerView.player)
Video Tracks

Video tracks are most helpfull when dealing with different renditions or different streams per video quality.

To select an video track simply follow the same principles as an audio track.

    @IBOutlet weak var playerView: VersaPlayer!

    ...
    
    let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.videoTracks
    /// the name of the track
    let name = tracks.first?.name
    /// selecting the first one
    tracks.first?.select(for: playerView.player)
Caption Tracks

Caption tracks are almost always helpfull. This can be used from a movie playback all the way to assitive content.

To select an video track simply follow the same principles as video and audio tracks.

    @IBOutlet weak var playerView: VersaPlayer!

    ...
    
    let tracks: [VersaPlayerMediaTrack] = playerView.player.currentItem?.captionTracks
    /// the name of the track
    let name = tracks.first?.name
    /// the language of the track
    let name = tracks.first?.language
    /// selecting the first one
    tracks.first?.select(for: playerView.player)
Caption Styling

Caption styling are not usually managed by the user, but when necessary, captionStyling property from VersaPlayer comes in handy.

Explore all the available attributes that can be changed here:

https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/Classes/VersaPlayerCaptionStyling.html

Extensions

Versa is aimed to be versatile, and that's why it comes with an extensions feature, that lets you customize any aspect of the player by inheriting from VersaPlayerExtension.

This class comes with a player attribute that points to the player instance from which is being used. To add an extension use the add(extension ext:) method found in https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/Classes/VersaPlayer.html.

Here are some extensions for VersaPlayer that may be useful for you.

  1. AirPlay Extension

  2. Ads Extension

  3. Overlay Content Extension

Documentation

Full documentation avilable https://josejuanqm.github.io/Libraries-Documentation/VersaPlayerCore/

Author

Jose Quintero - [email protected]

Contributors

People that make VersaPlayer possible, Thank you!

josejuanqm pbeast danibachar HuseyinVural

Donation

If you like this project or has been helpful to you, you can buy me a cup of coffe :) Appreciate it!

paypal

License

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

Comments
  • having trouble adding controls to player

    having trouble adding controls to player

    Hi everyone, got the sample project to work, but no controls. how do I add controls to the player? do I have to do that programmatically or through storyboard?

    can someone show one example of at least one control.

    thank you

    opened by forTheSakeOfLogic 10
  • How to get notification while video playing ?

    How to get notification while video playing ?

    Hello thank you for your great plugin. I do love it I tired to get progress and duration total of videos but option in list features Please show me thank you

    opened by kristoff2016 9
  • Is it possible to set more height for player controls than the player view?

    Is it possible to set more height for player controls than the player view?

    Is it possible to set more height for player controls than the player view? I have attached a screenshot where you can see the player view is that black background colored part above pink one and above there is controls setup with more height that extends till pink color starting from player view top. The problem is with the setup is touch isn't repond on that pink part but responds on playerview part

    Screenshot 2020-03-02 at 3 33 26 PM

    **Desktop **

    • iOS
    inactive 
    opened by StackHelp 7
  • Not scrolling if put in scrollview after VideoPlayerControls disappears

    Not scrolling if put in scrollview after VideoPlayerControls disappears

    If I put VersaPlayer in scrollview, and if VideoPlayerControls view disappears, the scrolling doesn't work if the drag gesture starts from player's view. It does work if the dragging finger doesn't start from player but some other components of the scrollview.

    It does also work, if the controls are visible, as soon as they disappear, the scrolling no more works.

    enhancement 
    opened by RajChanchal 7
  • Gesture not working

    Gesture not working

    I add my gesture in viewDidLoad(), but it does not work till tapping to make osd on

    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(handleGesture)) swipeRight.direction = .right self.view.addGestureRecognizer(swipeRight)

    needs:reply 
    opened by frozenthrone 7
  • Unexpectedly found nil

    Unexpectedly found nil

    handler.playbackDelegate?.playbackReady(player: self)

    sometimes it gives me this crash. my apps first screen has one player, second screen has another player. when i push second and fast pop back, it gives me this crash. image

    bug 
    opened by asger777 6
  • App crash while setting PlayerItem to Player.

    App crash while setting PlayerItem to Player.

    First of thanks for the excellent library.

    When I try to install it via pod it install with "1.2.0" and VersaPlayerItem becomes to VPlayerItem and when I see both files then there's only 1 line of code public var isEncrypted: Bool = false

    when I use below code then it crash at player.set(item: item) line of code with below bad access error.

    Thread 1: EXC_BAD_ACCESS (code=1, address=0x0)

    override func viewDidLoad() {
            super.viewDidLoad()
            
            player.use(controls: controls)
            if let url = URL.init(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8") {
                let item = VPlayerItem(url: url)
                player.set(item: item)
            }
        }
    

    do I miss something or is there any issue with version?

    bug 
    opened by StellarKuldeep 6
  • Can't initialize player, please help

    Can't initialize player, please help

    Hello! When I try to initialize the player in the vc, the app crashes with this error

    Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value on playerView.layer.backgroundColor = UIColor.black.cgColor

    I am doing exactly everything as the example code, I literally copied it.Also tried to clone the repo and run the example player, which works, but when I create a view controller in my app, and navigate to it the app still crashes...

    Current code im using: `import UIKit import VersaPlayer

    class ViewController: UIViewController {

    @IBOutlet weak var playerView: VersaPlayerView!
    @IBOutlet weak var controls: VersaPlayerControls!
    
    @IBAction func trigger(_ sender: UIButton) {
        print("test")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        playerView.layer.backgroundColor = UIColor.black.cgColor
        playerView.use(controls: controls)
        
        if let url = URL.init(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8") {
            let item = VersaPlayerItem(url: url)
            playerView.set(item: item)
        }
    }
    

    }`

    Also tried version 2.2.3 of the player, and with swift 4 and 4.2, still no luck..

    Any idea what could it be?

    needs:reply 
    opened by mblrdev 5
  • Can I use Carthage?

    Can I use Carthage?

    Could not believe cocoapods have to download ~500MB only to be able to install this library. I only use Carthage for all libraries in my project. Is it possible to use carthage in addition to pods?

    opened by mtangoo 5
  • Video Controls not showing

    Video Controls not showing

    Hi everyone, @josejuanqm

    why video control not showing just video playing and no play or pause or seek bar ?

    this is my code its same as example:

    import UIKit
    import VersaPlayer
    
    class ViewController: UIViewController {
    
        @IBOutlet weak var playerView: VersaPlayerView!
        @IBOutlet weak var controls: VersaPlayerControls!
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            if let url = URL.init(string:  "https://www.w3schools.com/html/movie.mp4") {
                let item = VersaPlayerItem(url: url)
                playerView.set(item: item)
            }
            
            playerView.layer.backgroundColor = UIColor.black.cgColor
            playerView.use(controls: controls)
        }
    
    }
    

    do i miss something ? show i enable or do more to show video controls ?

    opened by 3m1o 5
  • Error when embedding player in SwiftUI

    Error when embedding player in SwiftUI

    Using below snippet to embed the player in SwiftUI

    import SwiftUI
    import VersaPlayer
    
    struct StructPlayerView: UIViewRepresentable {
        typealias UIViewType = VersaPlayerView
        let url: String
        
        func makeUIView(context _: UIViewRepresentableContext<StructPlayerView>) -> VersaPlayerView {
            VersaPlayerView()
        }
        
        func updateUIView(_ uiView: VersaPlayerView, context _: UIViewRepresentableContext<StructPlayerView>) {
            uiView.set(item: VersaPlayerItem(url: URL(string: url)!))
            uiView.layer.backgroundColor = UIColor.black.cgColor
            uiView.use(controls: VersaPlayerControls())
        }
    }
    

    Bug Running on AppleTV 4K, the player view opens with a black screen with no activity in the logs or on screen. No controls are visible on swiping on appletv remote. Pressing play/pause button throws Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

    Device:

    • Device: AppleTV 4K
    • OS: tvOS 14.0.2
    no-issue-activity 
    opened by pharshdev 4
Releases(3.0.0)
Owner
Jose Quintero
iOS Developer made in Guatemala
Jose Quintero
Yattee: video player for Invidious and Piped built for iOS, tvOS and macOS

Video player for Invidious and Piped instances built for iOS, tvOS and macOS. Features Native user interface built with SwiftUI Multiple instances and

Yattee 1.1k Jan 8, 2023
YouTube video player for iOS, tvOS and macOS

About XCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS. Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also a

Cรฉdric Luthi 2.9k Jan 7, 2023
โ–ถ๏ธ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Jan 2, 2023
IINA is the modern video player for macOS.

IINA IINA is the modern video player for macOS. Website ยท Releases ยท Telegram Group Features Based on mpv, which provides the best decoding capacity o

Jesse Chan 0 Nov 2, 2021
Musical Player - A Simple Musical Player For iOS

Musical_Player The app is a musical player. It was written as an task for a mobi

null 1 Nov 26, 2022
iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

Abe Wang 11 Nov 7, 2022
๐Ÿ“ฝ A video player for SwiftUI, support for caching, preload and custom control view.

Features QuickStart Advances Installation Requirements License Demo Clone or download the project. In the terminal, run swift package resolve. Open Vi

Gesen 437 Jan 5, 2023
YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI for easily create a Youtube app

YoutubeKit YoutubeKit is a video player that fully supports Youtube IFrame API and YoutubeDataAPI to easily create Youtube applications. Important Ref

Ryo Ishikawa 555 Dec 28, 2022
WatchTube: a standalone WatchOS youtube player utilizing Download API for search data and video streaming

WatchTube is a standalone WatchOS youtube player utilizing Download API for sear

WatchTubeTeam 11 May 30, 2022
BMPlayer - A video player for iOS, based on AVPlayer, support the horizontal, vertical screen

A video player for iOS, based on AVPlayer, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, support subtitles.

Eliyar Eziz 1.8k Jan 4, 2023
Swifty360Player - iOS 360-degree video player streaming from an AVPlayer.

Swifty360Player iOS 360-degree video player streaming from an AVPlayer. Demo Requirements Swifty360Player Version Minimum iOS Target Swift Version 0.2

Abdullah Selek 148 Dec 18, 2022
VGPlayer - ๐Ÿ“บ A simple iOS video player by Vein.

Swift developed based on AVPlayer iOS player,support horizontal gestures Fast forward, pause, vertical gestures Support brightness and volume adjustment, support full screen, adaptive screen rotation direction.

Wen Rong 399 Dec 23, 2022
Open Source iOS 360 Degree Panorama Video Player.

?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? The Metal with Swift 5.0 version is comming ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 360 VR Player A Open Source, Ad-free, Na

Hanton Yang 2k Dec 24, 2022
FWVideoPlayer is video Player for iOS in Swift.

FWVideoPlayer Desc FWVideoPlayer is video Player for iOS in Swift. It can play video and audio. You can use it easy. Example To run the example projec

null 1 Oct 15, 2021
360 video player for iOS written in swift - a subset of SceneKit that works

DDDKit An open source library to support 360 videos and pictures. It's designed as a generic 3D library that you can use for much more! Example of use

Guillaume Sabran 123 Aug 9, 2022
Overlay alpha channel video animation player view using Metal.

Overlay alpha channel video animation player view using Metal. Example To run the example project, clone the repo, and run pod install from the Exampl

noppefoxwolf 244 Jan 1, 2023
SuperVideoPlayer is video player in Objc.

SuperVideoPlayer Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation S

null 1 Oct 19, 2021
YHPlayer - An easy-to-use video player based on swift language

YHPlayer An easy-to-use video player based on swift language Features Plays loca

null 9 Dec 1, 2022
Video mp4 record save display - How to Take , Save and Display a .mp4 Video

Technicalisto How to Take , Save and Display a .mp4 Video Add your design with v

Aya Baghdadi 2 Aug 7, 2022