▶️ video player in Swift, simple way to play and stream media on iOS/tvOS




Player is a simple iOS video player library written in Swift.

Build Status Pod Version Swift Version GitHub license

Need a different version of Swift?

  • 5.0 - Target your Podfile to the latest release or master
  • 4.2 - Target your Podfile to the swift4.2 branch
  • 4.0 - Target your Podfile to the swift4.0 branch


  • plays local media or streams remote media over HTTP
  • customizable UI and user interaction
  • no size restrictions
  • orientation change support
  • simple API
  • video frame snapshot support

Quick Start

Player is available for installation using the Cocoa dependency manager CocoaPods. Alternatively, you can simply copy the Player.swift file into your Xcode project.

# CocoaPods
pod "Player", "~> 0.13.2"

# Carthage
github "piemonte/Player" ~> 0.13.2


The sample project provides an example of how to integrate Player, otherwise you can follow these steps.

Allocate and add the Player controller to your view hierarchy.

 self.player = Player()
 self.player.playerDelegate = self
 self.player.playbackDelegate = self
 self.player.view.frame = self.view.bounds

 self.player.didMove(toParent: self)

Provide the file path to the resource you would like to play locally or stream. Ensure you're including the file extension.

let videoUrl: URL = // file or http url
self.player.url = videoUrl



Adjust the fill mode for the video, if needed.

 self.player.fillMode = .resizeAspectFit

Display video playback progress, if needed.

extension ViewController: PlayerPlaybackDelegate {

    public func playerPlaybackWillStartFromBeginning(_ player: Player) {

    public func playerPlaybackDidEnd(_ player: Player) {

    public func playerCurrentTimeDidChange(_ player: Player) {
        let fraction = Double(player.currentTime) / Double(player.maximumDuration)
        self._playbackViewController?.setProgress(progress: CGFloat(fraction), animated: true)

    public func playerPlaybackWillLoop(_ player: Player) {
        self. _playbackViewController?.reset()



You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.




Player is available under the MIT license, see the LICENSE file for more information.

  • Issue Playing Local Files

    Issue Playing Local Files

    Hi, Love the Library - Just having a confusing issue - I am also using your NextLevel Camera Library and Player will not display the merged or exported local clips (This also seems to be the case for other local files.) The Implementation is fine, as I have checked that both Player can display remote URL's in the view and that a standard AVPlayer can play the problematic local files. Just curious if this is a known bug or If I am missing something?


    opened by efbsecond 12
  • Problem multiple video

    Problem multiple video

    Hi @piemonte !

    I'm trying to use your lib with a TinderSimpleSwipeCards ( https://github.com/cwRichardKim/TinderSimpleSwipeCards )

    This is the fastest video lib I've found.

    However, when i create 16 card ( 16 Player ), the 17th is not displayed ... , and i dont know why.

    But it works, if i press the home button, then i go back to the application... .

    Any idea ?

    opened by Ze-ro-G 12
  • Most efficient way to play a queue of videos?

    Most efficient way to play a queue of videos?

    Is it possible to play the videos without a gap? Also, how can I minimize memory consumption by reusing the player?

        func playVideo() {
            videoPlayerController.videoPath = self.videoPath;
            // present
            // Start Video
            //videoPlayerController.playbackLoops = true;
        func videoPlayerPlaybackDidEnd(videoPlayer: PBJVideoPlayerController!) {
            // setup next video and call self.playVideo()

    This might be of some interest: https://github.com/katokichisoft/SimpleGaplessPlayer

    opened by switz 12
  • Using player inside a custom TableViewCell

    Using player inside a custom TableViewCell

    Hey Patrick. First things first, thanks for an awesome library, really =)

    Basically, I am trying to implement a Vine-like app which will have a video player inside each cell and other buttons for likes, sharing et cetera. What is your opinion about this and do you think that is this possible with the current design of the library itself?

    opened by ghost 10
  • Improvements: fillMode as Enums

    Improvements: fillMode as Enums

    It is hard to find which fill modes are supported when they are as strings.

    self.player.fillMode = “AVLayerVideoGravityResizeAspect”

    Could you please add the possible fill modes to the documentation or make them available with an enum?

    opened by confile 8
  • deinit not called when using this library?

    deinit not called when using this library?

    I am running into performance issues in my app and I believe they are related to this library, or at least how I am using it.

    I noticed that deinit is never called on the controller that implements Player!

    I have tried a lot of methods for getting it to fire and nothing seems to work:

    dispatch_async(dispatch_get_main_queue()) { if self.player != nil{ self.player!.pause() self.player!.stop() self.player!.view.removeFromSuperview() self.player!.delegate = nil self.player = nil } self.dismissViewControllerAnimated(true, completion: { _ in })

    this helps with memory but does not completely remove the viewController. any ideas?

    opened by uknowmeright 6
  • resuming video doesn't load the video on the exact time

    resuming video doesn't load the video on the exact time


    The Issue I am currently facing is regarding the resuming video from saved time. I am saving the time and when the user launches the same video I am seeking it to that instance of time but the video is not played from the exact time rather its played before some seconds ranging from 1 to 9.

    Here is one scenario, the video saved time is 600 seconds i.e 10 mins and when the video is played, I am playing the video from saved Time interval by seeking to that time using player.seek(to: timeInterval) where timeInterval is of type CMTIME with value as 600 and then I do player.playFromCurrentTime() which will start playing the video from the time stamp I sought to But the video plays from 9:51 ie 591 seconds. Hope I will get an early response.


    opened by majeedyaseen 5
  • Solve issue#166 and 'playbackPausesWhenBackgrounded' doesn't work well.

    Solve issue#166 and 'playbackPausesWhenBackgrounded' doesn't work well.

    Hello! I have been developing an app lately using Player😸


    I found a problem that playbackPausesWhenBackgrounded property doesn't work well. And I found the cause of the problem.

    When pressed the Home button, Player receives UIApplicationWillResignActive notification before receives UIApplicationDidEnterBackground notification. Current handler method for UIApplicationWillResignActive is following. Therefore Player always pauses when background.

    @objc internal func handleApplicationWillResignActive(_ aNotification: Notification) {
        if self.playbackState == .playing {

    Also, I read issue #166. This PR is a solution for these two problem.


    Add playbackPausesWhenResigningActive and playbackResumesWhenBecameActive properties just like playbackPausesWhenBackgrounded and playbackResumesWhenEnteringForeground. And Player controls properly when receive UIApplication notifications.

    Please review🙇

    opened by 131e55 5
  • Snapchat like video preview

    Snapchat like video preview

    @piemonte I would like to be able to instantly show a preview of a video taken by the user - just like Snapchat and more impressive, Instagram stories. Somehow once a user stops capturing a video on both apps, a preview automatically starts playing in an endless loop seemingly within the same view.

    How can I achieve that with Player?

    opened by otymartin 5
  • Fix Carthage Installation

    Fix Carthage Installation

    This does 2 things to fix carthage installations:

    • [x] Share the main Player scheme
    • [x] Duplicate the Player.h umbrella file and rename each to match one of the targets

    Closes #144

    opened by eliotfowler 4
  • Allow setting up Player from local AVAsset

    Allow setting up Player from local AVAsset

    We have an AVAsset from our capture tool. It seems silly to write it to a file just to play it so we made a slight modification to allow setting up the player using the premade Asset.

    Would love to get your feedback!

    opened by eliotfowler 4
  • Player may be crash.

    Player may be crash.

    Thread 0 name: Dispatch queue: com.apple.main-thread Thread 0 Crashed: 0 libobjc.A.dylib 0x00000001b290e4ac object_isClass + 16 1 Foundation 0x00000001b2faa5f8 KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED + 44 2 Foundation 0x00000001b2fa8120 NSKeyValueWillChangeWithPerThreadPendingNotifications + 272 3 AVFoundation 0x00000001bce0aa14 __31-[AVPlayerItem _updateTimebase]block_invoke_2 + 180 4 libdispatch.dylib 0x00000001b28b29a8 dispatch_call_block_and_release + 24 5 libdispatch.dylib 0x00000001b28b3524 dispatch_client_callout + 16 6 libdispatch.dylib 0x00000001b28966fc dispatch_main_queue_callback_4CF$VARIANT$armv81 + 860 7 CoreFoundation 0x00000001b2b6b6bc CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 12 8 CoreFoundation 0x00000001b2b66590 __CFRunLoopRun + 1724 9 CoreFoundation 0x00000001b2b65ba8 CFRunLoopRunSpecific + 424 10 GraphicsServices 0x00000001bccd5344 GSEventRunModal + 160 11 UIKitCore 0x00000001b6ca13e4 UIApplicationMain + 1932 12 libswiftUIKit.dylib 0x00000001e97dc2b4 UIApplicationMain+ 45748 (::::) + 168 13 Blessed 0x000000010454dd04 static UIApplicationDelegate.main() + 56580 (:0) 14 Blessed 0x000000010454dc8c static AppDelegate.$main() + 56460 (:0) 15 Blessed 0x000000010454e110 main + 57616 (AppDelegate.swift:0) 16 libdyld.dylib 0x00000001b29ed8f0 start + 4

    opened by ZHDeveloper 0
  • Not working

    Not working

    Hello, I added the following code in the viewDidLoad

        override func viewDidLoad() {
            self.player.playerDelegate = self
            self.player.playbackDelegate = self
            self.player.url = URL(string: "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-15.mp3")!

    and added IBaction to play the audio using the below

        @IBAction func playButtonPressed(_ sender: UIButton) {
           // print(self.player.view)

    But unfortunatley , this is not working until I add the code below


    This will load the Player class into memory and it will unlock the isViewLoaded

    How can this be fixed and the audio don't play automatically unless the user click in Play Button

    opened by sam961 0
  • Setting up Player with AVPlayerItem.

    Setting up Player with AVPlayerItem.

    Player stopped working when set up with an AVAsset downloaded from user's iCloud photo library using PHImageManager:

    Error Domain=NSCocoaErrorDomain Code=257 UserInfo={NSURL=file:///var/mobile/Media/PhotoData/Metadata/DCIM/101APPLE/IMG_1858.small.MP4, NSUnderlyingError=0x2833487b0 {Error Domain=NSOSStatusErrorDomain Code=-12203 "(null)"}}

    Related posts:

    Swift AVAsset downloading from iCloud has no permission on iOS 14: error Code=257

    Request AVAsset using iCloud PHAsset returns an AVAsset with no VideoTracks


    Set up Player with an AVPlayerItem.

    PHImageManager provides either an AVAsset or an AVPlayItem for a video request from user's photo library. This issue does not occur when working with an AVPlayerItem.

    opened by lurui1029 0
patrick piemonte
if it ain't broke, fix it.
patrick piemonte
Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey

Video player with support for Invidious and Piped instances built for iOS 15, tvOS 15 and macOS Monterey.

Yattee 1k Dec 27, 2022
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
Versatile Video Player implementation for iOS, macOS, and tvOS

News ?? - Since 2.1.3 VersaPlayer now supports iOS, macOS, and tvOS Example Installation Usage Basic Usage Adding Controls Advanced Usage Encrypted Co

Jose Quintero 723 Dec 26, 2022
MobilePlayer - A powerful and completely customizable media player for iOS

MobilePlayer A powerful and completely customizable media player for iOS. Table of Contents Features Installation Usage Customization Skinning Showing

Sahin Boydas 3k Jan 2, 2023
A powerful and completely customizable media player for iOS

MobilePlayer A powerful and completely customizable media player for iOS. Table of Contents Features Installation Usage Customization Skinning Showing

Sahin Boydas 3k Jan 2, 2023
VLC media player

VLC media player VLC is a libre and open source media player and multimedia engine, focused on playing everything, and running everywhere. VLC can pla

VideoLAN 10.1k Dec 24, 2022
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
Audio player demo based on Swift and SwiftUI, which can play local or network audio.

SwiftAudioDemo Audio player demo based on Swift and SwiftUI, which can play local or network audio. In this demo, I have made a radio player to play n

Jensen Zhang 6 Mar 13, 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
An iOS application 📱 that extracts text real time using camera 📷 and play relevant video from the text

CHARUSAT-SceW It is an iOS application ?? that scans and extracts text real-time through camera ?? , if it is detected. It will play relevent video fr

Vatsal Patel 2 Nov 15, 2021
DelayStream - A swift version to stream a file or stdin one line at a time with a delay

DelayStream A swift version to stream a file or stdin one line at a time with a

Keanu Pang 0 Jan 28, 2022
📹 Framework to Play a Video in the Background of any UIView

SwiftVideoBackground is an easy to use Swift framework that provides the ability to play a video on any UIView. This provides a beautiful UI for login

Wilson Ding 333 Nov 23, 2022
Official SwiftUI SDK for Stream Chat.

SwiftUI - Currently in Development ?? The SwiftUI SDK is built on top of the StreamChat framework and it's a SwiftUI alternative to the StreamChatUI S

Stream 136 Dec 23, 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
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
📽 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