VIMVideoPlayer is a simple wrapper around the AVPlayer and AVPlayerLayer classes.

Related tags

Video VIMVideoPlayer
Overview

⚠️ ⚠️ ⚠️ This library has been deprecated and will be removed in the future. Use PlayerKit instead. ⚠️ ⚠️ ⚠️

VIMVideoPlayer

VIMVideoPlayer is a simple wrapper around the AVPlayer and AVPlayerLayer classes.

Setup

Add the VIMVideoPlayerView and VIMVideoPlayer classes to your project.

Do this by including this repo as a git submodule or by using cocoapods:

# Add this to your podfile
target 'MyTarget' do
   pod 'VIMVideoPlayer', {CURRENT_POD_VERSION}
end

Usage

Create a new VIMVideoPlayerView instance or set up an @IBOutlet:

@IBOutlet weak var videoPlayerView: VIMVideoPlayerView!

...

override func viewDidLoad()
{
    // Configure the player as needed
    self.videoPlayerView.player.looping = true
    self.videoPlayerView.player.disableAirplay()
    self.videoPlayerView.setVideoFillMode(AVLayerVideoGravityResizeAspectFill)
    
    self.videoPlayerView.delegate = self
}

Play a video:

// Using an NSURL

if let path = NSBundle.mainBundle().pathForResource("waterfall", ofType: "mp4")
{
    self.videoPlayerView.player.setURL(NSURL(fileURLWithPath: path))
}
else
{
    // Video file not found!
}

/* 
  Note: This must be a URL to an actual video resource (e.g. http://website.com/video.mp4 or .m3u8 etc.),
  It cannot be a URL to a web page (e.g. https://vimeo.com/67069182),
  See below for info on using VIMVideoPlayer to play Vimeo videos.
*/

// Using an AVPlayerItem

let playerItem: AVPlayerItem = ...
self.videoPlayerView.player.setPlayerItem(playerItem)
self.videoPlayerView.player.play()

// Or using an AVAsset

let asset: AVAsset = ...
self.videoPlayerView.player.setAsset(asset)
self.videoPlayerView.player.play()

Optionally implement the VIMVideoPlayerViewDelegate protocol methods:

protocol VIMVideoPlayerViewDelegate 
{    
    optional func videoPlayerViewIsReadyToPlayVideo(videoPlayerView: VIMVideoPlayerView!)
    optional func videoPlayerViewDidReachEnd(videoPlayerView: VIMVideoPlayerView!)
    optional func videoPlayerView(videoPlayerView: VIMVideoPlayerView!, timeDidChange cmTime: CMTime)
    optional func videoPlayerView(videoPlayerView: VIMVideoPlayerView!, loadedTimeRangeDidChange duration: Float)
    optional func videoPlayerViewPlaybackBufferEmpty(videoPlayerView: VIMVideoPlayerView!)
    optional func videoPlayerViewPlaybackLikelyToKeepUp(videoPlayerView: VIMVideoPlayerView!)
    optional func videoPlayerView(videoPlayerView: VIMVideoPlayerView!, didFailWithError error: NSError!)
}

See VIMVideoPlayer.h for additional configuration options.

Playing Vimeo Videos

Vimeo Pro members can access playback URLs for Vimeo videos using the Vimeo API. Playback URLs are only included in the response object if the requesting account is a Vimeo Pro account.

If you have a Vimeo Pro account, when you make a request to the Vimeo API for a video object the response object will contain a list of video files. These represent the various resolution video files available for this particular video. Each has a link. You can use the string value keyed to link to create an NSURL. You can pass this NSURL to VIMVideoPlayer for playback.

Check out this Stack Overflow question for additional info.

You can use the Vimeo iOS SDK to interact with the Vimeo API.

For full documentation on the Vimeo API go here.

Found an Issue?

Please file it in the git issue tracker.

Want to Contribute?

If you'd like to contribute, please follow our guidelines found in CONTRIBUTING.md.

License

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

Questions?

Tweet at us here: @vimeoapi.

Post on Stackoverflow with the tag vimeo-ios.

Get in touch here.

Interested in working at Vimeo? We're hiring!

Comments
  • VIM-4496: No Playback if Already in Airplay Mode

    VIM-4496: No Playback if Already in Airplay Mode

    Ticket

    Required for Vimeans only VIM-4496

    Ticket Summary

    To support DRM, we need to directly access the player asset and set its delegate. See changes to playVideoWithURL: captured here: https://github.vimeows.com/MobileApps/Vimeo-iOS/pull/938/files

    As a result, we're now using setAsset: instead of setURL:. This left local playback unaffected. But in airplay mode, the player never received a status change that the player item was ready to play. (If a video was already playing, it could be air played, but the next video would not play).

    It's not clear why this was happening, but the way in which we create the asset seems like it could be the culprit. The init method we used specified that we should pre-load "tracks". This in effect excluded "duration" as a key to be preloaded. The docs say:

    "Unless you omit @"duration" from the array of asset keys you pass to 
    +playerItemWithAsset:automaticallyLoadedAssetKeys: or -initWithAsset:automaticallyLoadedAssetKeys:, 
    the value of this property will accord with the properties of the underlying AVAsset 
    and the current state of playback once the receiver becomes ready to play."
    

    It's interesting that the most basic player Item creation method playerItemWithAsset (which is what this PR suggests we use) does not exclude the duration key. The docs say that calling playerItemWithAsset is equivalent to +playerItemWithAsset:automaticallyLoadedAssetKeys: and passing @[ @"duration" ] as the value of automaticallyLoadedAssetKeys.

    Also, it's not clear if we necessarily need to pre-load tracks because it seems we don't need to access them outside of the context of playback. The docs say

    If you need to access information about the asset before you enqueue it for playback, 
    you can use the methods of the AVAsynchronousKeyValueLoading protocol to load 
    the values you need. Alternatively, AVPlayerItem can automatically load the 
    needed asset data for you by passing the desired set of keys 
    to its init(asset:automaticallyLoadedAssetKeys:) initializer. When the player item is ready 
    to play, those asset properties will have been loaded and are ready for use.
    

    From an older WWDC talk - 2014

    If you anticipate the use of a particular property later in your application, 
    you can still request all of them together using loadValuesAsynchronouslyForKeys and 
    completionHandler. You can parse in an array of keys which AVFoundation will load together and 
    your completionHandler is called once you are done loading these properties. 
    You no longer have to load tracks before playback begins. 
    This has changed since the last time we talked about best practices. 
    In fact, this has changed since iOS 5. You really only need to load those properties you 
    would directly use in your application.
    

    Since I couldn't find a clear link between our playback flow, airplay, and the creation of assets, the snippets above were meant to show it's likely not necessary to preload tracks, it could be disrupting something in our current playback flow and we can adopt the simpler method.

    Implementation Summary

    Updated the init method used for creating our AVAsset.

    How to Test

    • Confirm local playback works as expected.
    • Enable airplay and connect to an Apple TV. Confirm playback works normally on external screen and "streaming to airplay" UI is on your device. Confirm you can tap a new video while already in airplay and playback is normal. Note, it's normal for the device to appear as though it is intermittently disconnecting and reconnecting as the user is switching videos.
    opened by nicolelehrer 3
  • Where I get URL to mp4

    Where I get URL to mp4

    From docs it is unclear where I should get reference on MP4 file. I don't want to use https://player.vimeo.com/video/<video_id>/config to get this information and have strong believe what there is more preferable and legal ay to get it.

    How do I get path to MP4 which can be used with this player?

    Best regards, Sergey

    opened by parfeon 3
  • Play multi videos

    Play multi videos

    Hi, I have a list of vimeo, my flow is: for vimeo in list { fetch vimeo direct url play vimeo with VIMVideoPlayer }

    I have a VIMVideoPlayer to reuse But I don't known how to switch to other url? I try this, but not work:

    • (void)playVideoVimeo: (NSURL*)url { [_vimeoPlayerView.player setURL:url]; [_vimeoPlayerView.player play]; }

    I tried to new 1 view for every video but I got other issue: the audio go first 2s after then is image. So with video about 2s, I don't see anything, only hear the sound.

    I use xcode 6.4 simulator 8.4

    Thanks.

    opened by thienchau 3
  • VIM-4419: DRM player error UI

    VIM-4419: DRM player error UI

    Ticket

    https://vimean.atlassian.net/browse/VIM-4419

    Ticket Summary

    This implements UI states for DRM-specific errors in the player.

    Implementation Summary

    Since NSErrors from a failed AVAssetResourceLoadingRequest are propagated back to our video player as an underlying error, I added steps to select the appropriate error object in our status observer KVO.

    It's kind of a bummer that an NSObject can come from three different places (Who is to say which one we want to forward on?) but this seems like a reasonable selection process.

    Associated PR: https://github.vimeows.com/MobileApps/Vimeo-iOS/pull/960

    How to Test

    See associated PR.

    opened by ghking 2
  • VIM-3864: Offline playback crash

    VIM-3864: Offline playback crash

    Ticket

    Required for Vimeans only VIM-3864 See last comment by Dina

    Ticket Summary

    See companion PR

    Implementation Summary

    Check if seek to zero was successful before executing remainder of completion block

    How to Test

    See companion PR

    opened by nicolelehrer 2
  • Adds Framework Project to Workspace

    Adds Framework Project to Workspace

    Ticket

    No ticket

    Ticket Summary

    Source files were being compiled straight in the example project. Is there an alternative?

    Implementation Summary

    This pull request adds a framework project to the workspace so that the library can be compiled and worked on in the context of the framework project. And then consumed in the example project.

    How to Test

    Open the workspace.

    Build the framework project. Confirm there are no warnings or errors.

    Build and run the example project. Confirm there are no warnings or errors. Confirm it functions properly in the simulator and on device.

    opened by alfiehanssen 2
  • Added information on Vimeo video playback to the README

    Added information on Vimeo video playback to the README

    There's no documentation on developer.vimeo.com that explains that video file information is only included in the response object for a video if the account making the request is a Vimeo Pro account. That documentation is apparently in the works (cc @Dashron).

    In an effort to stem confusion, this PR adds info related to this to the README.

    opened by alfiehanssen 2
  • Question: Audio Selection

    Question: Audio Selection

    Hi, I want to add audio selection in the player without modifying your code. What would be the clean way to approach this.

    PS: I know how to change the audio via selectMediaOption. I just want to know how you guys would approach this. Would you place the code in the ViewController, in the delegate videoPlayerViewIsReadyToPlayVideo? or is there a cleaner approach?

    PPS: I don't have deliverables, I'm just trying to learn how to make simple and clean code. And I like your approach.

    opened by ninokierulf 2
  • VIM-4503: Session time

    VIM-4503: Session time

    Ticket

    https://vimean.atlassian.net/browse/VIM-4503

    Ticket Summary

    The current play logging events require session_time to be sent with the exit and play events. session_time is the total time the user has spent watching the video with the video actually playing. This ticket is for adding that parameter to those requests. Play logging spec here:

    https://docs.google.com/document/d/1B4FPhSK_TECdygjgRhGLFx9vZUeg-9zePOqV5zD5RF0/edit#

    This is a temporary implementation since we'll be overhauling our play logging with the new, unfinished spec that will be built by the API in the next few sprints.

    Implementation Summary

    Moving the TimeUpdateInterval constant to the header. This makes sense since as a user of this class, you can enable and disable time updates. It makes sense that you should be able to see at what interval these updates fire.

    Also changed the name of this constant from TimeObserverInterval to TimeUpdateInterval to match the enableTimeUpdates and disableTimeUpdates function names.

    Associated PR: https://github.vimeows.com/MobileApps/Vimeo-iOS/pull/951

    How to Test

    N/A

    opened by ghking 1
  • VIM-3520: Airplay Mirror Bug

    VIM-3520: Airplay Mirror Bug

    Ticket

    https://vimean.atlassian.net/browse/VIM-3520

    Ticket Summary

    The "Connected to AirPlay" overlay is displayed when in AirPlay mirroring mode, not just when AirPlay streaming mode.

    Implementation Summary

    Added self.player.usesExternalPlaybackWhileExternalScreenIsActive = YES;, which causes the player to switch to AirPlay streaming when the device is AirPlay mirroring when playing a video.

    How to Test

    See ticket.

    opened by ghking 1
  • VIM-3653: Example Project

    VIM-3653: Example Project

    Ticket

    https://vimean.atlassian.net/browse/VIM-3653

    Ticket Summary

    Add a demo project to VIMVideoPlayer.

    Implementation Summary

    Added a demo project for iOS that implements initializing a video, play/pause, and scrubbing.

    opened by ghking 1
  • Stop linking to this library from Vimeo API docs

    Stop linking to this library from Vimeo API docs

    Issue Summary

    The page https://developer.vimeo.com/api/libraries still references this repo but this repo states that it's deprecated.

    Reproduction Steps

    Visit https://developer.vimeo.com/api/libraries which links here. See that it is deprecated.

    Expected Behavior

    I expect https://developer.vimeo.com/api/libraries to point to the current recommended library. https://github.com/vimeo/PlayerKit

    Actual Behavior

    Linked here instead of to https://github.com/vimeo/PlayerKit

    opened by hawflakes 0
  • Cannot Open

    Cannot Open

    Issue Summary

    A brief but thorough description of the issue. vimeoPlayer.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: self.videoPlayer.bounds.height) vimeoPlayer.delegate = self self.videoPlayer.addSubview(vimeoPlayer) vimeoPlayer.player.disableAirplay() if let url = URL(string: "https://player.vimeo.com/video/12765955") { vimeoPlayer.player.setURL(url) } vimeoPlayer.player.isLooping = false vimeoPlayer.setVideoFillMode(AVLayerVideoGravity.resizeAspectFill.rawValue) vimeoPlayer.player.player.play()

    Above Code, I'm using to play Vimeo Video. When is ready to play I'm getting error Message

    Video player Status Failed: player item error = Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo={NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open, NSUnderlyingError=0x1c0856680 {Error Domain=NSOSStatusErrorDomain Code=-12847 "(null)"}}

    I check with URL link on Browser is fine it's working on the browser. kindly do needfully

    Reproduction Steps

    Detailed steps to reproduce the issue.

    Expected Behavior

    What do you expect to happen as a result of the reproduction steps?

    Actual Behavior

    What currently happens as a result of the reproduction steps?

    opened by syedrazackimran 1
  •  Scrub and seek should be smooth

    Scrub and seek should be smooth

    Issue Summary

    A brief but thorough description of the issue.

    Reproduction Steps

    Detailed steps to reproduce the issue.

    Expected Behavior

    What do you expect to happen as a result of the reproduction steps?

    Actual Behavior

    What currently happens as a result of the reproduction steps?

    opened by saikumarj 1
  • Example doesn't work

    Example doesn't work

    Check dependencies
    “Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.```
    opened by gerchicov-bp 2
Releases(6.0.1)
Owner
Vimeo
You know, for videos.
Vimeo
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
Player View is a delegated view using AVPlayer of Swift

PlayerView [![CI Status](http://img.shields.io/travis/David Alejandro/PlayerView.svg?style=flat)](https://travis-ci.org/David Alejandro/PlayerView) An

null 131 Oct 25, 2022
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
Gumlet analytics integration with AVPlayer for iOS native applications.

gumlet-Insights-avplayer Gumlet Insights integration with AVPlayer for iOS native applications. This Insights enables you to get useful data about vid

Gumlet 0 Dec 15, 2021
NYT360Video plays 360-degree video streamed from an AVPlayer on iOS.

NYT360Video 360º video playback from The New York Times NYT360Video plays spherical 360º video, allowing the user to explore the video via pan gesture

The New York Times 270 Nov 23, 2022
SuperPlayer is a library to wrap AVPlayer with Composable Architecture.

SuperPlayer is a library to wrap AVPlayer with Composable Architecture. It can be used in SwiftUI and UIKit.

Tokopedia 13 Dec 21, 2022
Pretty iOS mobile screens + AVPlayer video view ––– made in SwiftUI

UrbanVillageProjectScreens Recreated UI screens from the conceptual Urban Village Project. Read more about the project here. Please open an issue if y

10011.co 23 Dec 29, 2022
NYT360Video plays 360-degree video streamed from an AVPlayer on iOS.

NYT360Video 360º video playback from The New York Times NYT360Video plays spherical 360º video, allowing the user to explore the video via pan gesture

The New York Times 270 Nov 23, 2022
Thin SwiftUI wrapper around `yt-dlp`

SwiftyYTDL Thin SwiftUI wrapper around yt-dlp - popluar Python module for downloading stuff of Youtube, Twtitter, Instagram, TikTok and others. Depend

Danylo Kostyshyn 4 Dec 22, 2022
A Swift wrapper for the FFmpeg API

SwiftFFmpeg A Swift wrapper for the FFmpeg API. Note: SwiftFFmpeg is still in development, and the API is not guaranteed to be stable. It's subject to

sun_ 376 Nov 24, 2022
MacTube is a webview wrapper for YouTube for Mac OS.

MacTube MacTube is a webview wrapper for YouTube for Mac OS. It was made for peo

null 33 Dec 26, 2022
A video composition framework build on top of AVFoundation. It's simple to use and easy to extend.

A high-level video composition framework build on top of AVFoundation. It's simple to use and easy to extend. Use it and make life easier if you are implementing video composition feature.

VideoFlint 1.4k Dec 25, 2022
▶️ 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
A simple iOS app similar to iTunes where you can view details of your favorite movies, songs and audio books.

Popcorn Adventure This is an iOS app developed by Arthur Tristan M. Ramos who has taken the Appetiser iOS Coding Challenge. Design Pattern The design

Arthur Tristan M. Ramos 0 Dec 11, 2021
An advanced media player library, simple and reliable

About The SRG Media Player library provides a simple way to add universal audio / video playback support to any application. It provides: A controller

SRG SSR 144 Jul 22, 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
Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Simple macOS app that applies Apple's Person Segmentation algorithm to a video.

Fabio 5 Dec 9, 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
High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

High-performance and flexible video editing and effects framework, based on AVFoundation and Metal.

BearRuan 650 Dec 30, 2022