Code Monkey home page Code Monkey logo

versaplayer's Introduction

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.

versaplayer's People

Contributors

akisute avatar danibachar avatar eke avatar ezimetjan avatar huseyinvural avatar jose-quintero avatar josejuanqm avatar pbeast avatar rajchanchal avatar selvinn avatar srinivasprabhug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

versaplayer's Issues

Fullscreen from tableview cell

Hi,

I was playing around with your library by implementing a VersaPlayerView embedded inside a UITableViewCell. Just wondering if you are able to point me in the right direction on how I can have a background behind the video when I have expanded it so I can block out the view behind it?

Thanks

Normal view

Screen Shot 2019-09-10 at 9 35 00 am
Screen Shot 2019-09-10 at 9 35 36 am

Expanded View

Screen Shot 2019-09-10 at 9 35 11 am
Screen Shot 2019-09-10 at 9 35 49 am

add faster speed playback

Hi developer
do you have any plan to add faster speed playback option?
like 1.0x(original speed), 1.2x,1.5x, etc. speed to playback m3u8 videos

Landscape rotate

My app is restricted to portrait, but I would like enable rotation to landscape when in full screen mode. I have not been able to find if an override is provided here. Does VersaPlayer address this sort of thing? Great framework btw..

VersaPlayerPlaybackDelegate class type

Hey, please make VersaPlayerPlaybackDelegate of class type to avoid strong referencing. To change this please replace VersaPlayerPlaybackDelegate: AnyObject with VersaPlayerPlaybackDelegate: class

PFA fix screenshot.

screen shot 2019-01-08 at 1 31 02 pm

Thanks

Video Keeps playing in Background after dismissing the ViewController

When you enter fullscreen mode and back to normal mode. then you dismiss or pop the viewController Player keeps playing in the background which leads me to think the playerView is not released from Memory. This happens with the provided TestProject.
I think there is a retain cycle issue with the "nonFullscreenContainer" property, making it weak solved the problem for me.

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

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 ?

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

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?

Crash on Observer


Crash

You can easily reproduce if you quickly show/close the player. For now, I am adding guard for self object but please fix it in the next version.

Strong type delegate

Hey, VersaPlayerPlaybackDelegate is a strong type delegate thus preventing deinit of a ViewController from being called due to strong reference. Protocol should be class type and delegate should be weak. Can you please fix this issue at the earliest.

Thanks in advance.

PiP Mode Unavailable

How to make PiP work in iPhone? I know it's not supported but I think a library like this should implement its own PiP for within the app navigation.

Caching

Is there any caching mechanism for VersaPlay?

If so would like some tips on how to utilize it as it seems videos are always loaded no matter what.

Thanks!!

is there any way to open the video in fullscreen on landscape mode?

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Languages

I Did not see language control? Is there one in the 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?

Crashes sometimes

App crashes sometimes, attached is the screenshot from stack trace.
Any help?
Screen Shot 2019-11-26 at 9 19 19 AM

How to pass header attributes?

You can send one using 'AVURLAssetHTTPHeaderFieldsKey' in AVPlayer. Does VersaPlayer support. If yes, how? Please guide with example.

Cheers.

Unable to play local file

Does this support playing a file from file system?

My file URL: file:///Users/gerald/Library/Developer/CoreSimulator/Devices/28694CEC-DEE0-4E95-9302-F3962DDC63B6/data/Containers/Data/Application/620DDA30-4A41-484D-AED5-9FB334C1E9F2/Library/Caches/MyApp/28.mp4

I've tried ...
if let url = URL.init(string: movieFile.filename) { let asset = AVURLAsset(url: url) let item = VersaPlayerItem(asset: asset) playerView.set(item: item) }

and

let url = URL.init(fileURLWithPath: movieFile.filename) print("FILE URL: \(url)") let item = VersaPlayerItem(url: url) playerView.set(item: item)

Both return PlaybackDidFailed Error - Unknown
Am I doing something wrong?

how to add controls to player

@josejuanqm I want to start off by clarifying a few things, I was not trying to be disrespectful, nor do I understand where in the above message I was disrespectful. What I was, however, frustrated, not at you, but at my own ignorance/incompetence of not figuring it out. As for you, I have nothing but the highest respect for 1. spending the time to build this great project and providing it for free and 2. spending the time to continue to maintain it answer/fix issues.

As for your update, it works perfectly! thank you!!!!!

you my dear friend, have my highest respect!

wishing you a wonderful holiday season.

Originally posted by @forTheSakeOfLogic in #17 (comment)

Mute/Unmute?

How to mute/unmute player? Is there any control there for it?

Terminating app due to uncaught exception 'NSInternalInconsistencyException' only on iOS 10.3.3

Tested with a provided example by running Target VersaPlayerTest_iOS

Steps to produce the crash:
Step 1. Run project's target VersaPlayerTest_iOS on iOS 10.3.3 ( i used iPhone 6s)
Step 2. Tap on show video
Step 3. Tap on back button from the new view controller where the video is being played
and the app crashes!

Note: the app is working fine on my iOS 12.1 device

Crash Log:

1 <VersaPlayer.VersaPlayerView: 0x107e1b450; frame = (0 0; 375 667); autoresize = RM+BM; layer = <CALayer: 0x170227300>>
2 <VersaPlayer.VersaPlayerControlsCoordinator: 0x107d113b0; frame = (0 0; 375 667); layer = <CALayer: 0x174225aa0>>
3 <VersaPlayer.VersaPlayerGestureRecieverView: 0x107e31820; frame = (0 0; 375 667); gestureRecognizers = <NSArray: 0x170247680>; layer = <CALayer: 0x17022d240>>
4 <VersaPlayer.VersaPlayerControls: 0x107e06230; frame = (0 0; 375 667); autoresize = RM+BM; layer = <CALayer: 0x170226ca0>>
5 VersaPlayer.VersaPlayerControlsBehaviour
6 <VersaPlayer.VersaPlayerRenderingView: 0x107e07d30; frame = (0 0; 375 667); layer = <CALayer: 0x170229260>>
7 <VersaPlayer.VersaPlayerLayer: 0x170241ef0>
8 <VersaPlayer.VersaPlayerItem: 0x17022bde0, asset = <AVURLAsset: 0x17022bcc0, URL = https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8>>
9 <VersaPlayer.VersaPlayer: 0x1702419b0>
2019-04-02 00:38:57.968270+0530 VersaPlayerTest_iOS[16838:11201971] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x1702419b0 of class VersaPlayer.VersaPlayer was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x174220180> (
<NSKeyValueObservance 0x170242970: Observer: 0x1702419b0, Key path: status, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x170242850>
)'
*** First throw call stack:
(0x1823defe0 0x180e40538 0x1823def28 0x182e3b160 0x180e5e134 0x1822bab28 0x18238acec 0x1822bada4 0x183d25074 0x188575c9c 0x100031928 0x1812c959c)
libc++abi.dylib: terminating with uncaught exception of type NSException

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?

und nil while implicitly unwrapping an Optional value 2019-06-11 10:23:33.022373+0200 Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

hello
i try to launch a simple example
but playerView is null
my activity extend UIViewController ( built programmatically without storyboard )
i have the following error : Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
2019-06-11 10:23:33.022373+0200xxxxx[6256:1699778] Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

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

Xcode Theme

Do mine sharing the theme for Xcode?

Regarding the framework: nice work! Definitely going to give it a try in my project.

Thanks

Controls dissapear

If the screen is tapped, while the video is buffering the controls dissapear normally. But tapping again the controls do not appear and the video does not load. Almost as if the app has frozen

IB Designables: Failed to render and update auto layout status for VersaPlayerControls (wWX-7i-SUK): Failed to launch designables agent. Check the console for a more detailed description and please file a bug report at feedbackassistant.apple.com.

Xcode version: 11 Beta 2~4

There's a build error in red for the Full Screen Controls set stating: "IB Designables: Failed to render and update auto layout status for VersaPlayerControls (wWX-7i-SUK): Failed to launch designables agent. Check the console for a more detailed description and please file a bug report at feedbackassistant.apple.com."

The Full Screen Controls set were directly copied from the Example project file.

TV test app crashes on launch in tvOS 13

The sample TV app crashes on launch, with an error that seems nib related:

VersaPlayerTest_tvOS[69831:7967219] [Storyboard] Unknown class
_TtC20VersaPlayerTest_tvOS19VersaPlayerControls in Interface Builder
file.

It does not work with a local file.

I tried to play a local file but it does not work. Does the library support?

       let main = Bundle.main.path(forResource: "example", ofType: "mp4")!
        let url = URL(fileURLWithPath: main) 
        playerView.layer.backgroundColor = UIColor.black.cgColor
        playerView.use(controls: controls)
  
        let asset = AVURLAsset(url: url)
        let item = VersaPlayerItem(asset: asset)
        playerView.set(item: item)

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)

How to embedding a multiple video into a UITableViewCell ?

Hello thank you for your plugin. I have a problem. I want to use multiple video players on one screen. If I try to do this, all controls are running at the same time. As a result, the UISliders moves all videos.

What's the best way for embedding a video into a UITableViewCell? I'm trying to build something sorta like Twitter/Instagram.

Thank you.

How to create controls as programmatically?

Hi, I didn't use storyboard for create my video view, i've create view as programmatically. I can create video player with code and i can play video with that library. However i can't create controls with code how to create controls as programmatically?

Controls on tvOS without focus

Maybe i didn't understand well how to use the controls for the player. I have added some Buttons to the View, connected them to the Controls-Class. If i tap the touchfield on the AppleTV-Remote, the controls appears, but got no focus so you can't select or click a Button.

Local video support

Does it support to play a video from Bundle path?
If yes, then please help me to achieve that.

Can not toggle the fullscreen and how to replay?

Describe the bug
After I press the fullscreen button I can't toggle it back to normal screen.

To Reproduce
image
When i toggle the fullscreen button, it gives the message as in the image .

Another question is when it finished how to replay it through press some button?

Optional methods in VersaPlayerPlaybackDelegate

Hey, can you make methods of VersaPlayerPlaybackDelegate optional as we have to conform to all the methods even if we don't have to use it.
It's just a suggestion, if it is not possible due to some other reasons please let me know.

Thank you in advance.

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.

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.