VGPlayer - 📺 A simple iOS video player by Vein.

Overview

VGPlayer

Swift License MIT Platform Cocoapod Carthage compatible

Banners

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.

中文介绍

Demonstration

demo1

demo2

demo3

Requirements

  • Swift 3
  • iOS 8.0+
  • Xcode 8

Features

  • Support play local and network
  • Background playback mode.
  • Gesture Adjusts the volume and brightness as well as fast forward and backward.
  • Support full screen
  • Slide fast forward and backward
  • Lock screen can also be rotated full screen
  • Support replay media
  • Support custom player view
  • Support subtitle (format: srt & ass)
  • Media Cache

TODO

  • Virtual reality

Update

  • 2017-6-13 v0.0.1
  • 2017-6-17 Support subtitle (format: srt & ass) v0.0.2
  • 2017-7-1 Media Cache v0.1.0
  • 2017-7-3 fix some compiler warning, support carthage. v0.1.1
  • 2017-7-11 fix all compiler warning. v0.1.2
  • 2017-7-16 fix URL resolution error. v0.1.3
  • 2017-8-10
    • fix iOS 9 can't play
    • fix exit Full Screen frame error
    • player slider thumb add highted
    • example add demo
  • 2017-9-6 v0.1.5
    • fix url param praser
    • fix pause play error
  • 2017-9-21 v0.2.0
    • clean code
    • convert to swift4

Usage

Play Video

// init 
self.player = VGPlayer(URL: url)
// or
self.player.replaceVideo(url)

Custom player view

  • Subclass VGPlayerView
  • Alloc VGPlaye when set up
let playeView = VGCustomPlayerView()
self.player = VGPlayer(playerView: playeView)

// customPlayerView
class VGCustomPlayerView: VGPlayerView {
    var playRate: Float = 1.0
    var rateButton = UIButton(type: .custom)
    
    override func configurationUI() {
        super.configurationUI()
        self.topView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.09701412671)
        self.bottomView.backgroundColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 0.09701412671)
        self.topView.addSubview(rateButton)
        rateButton.snp.makeConstraints { (make) in
            make.left.equalTo(titleLabel.snp.right).offset(10)
            make.centerY.equalTo(closeButton)
        }
        rateButton.tintColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
        rateButton.setTitle("x1.0", for: .normal)
        rateButton.titleLabel?.font   = UIFont.boldSystemFont(ofSize: 12.0)
        rateButton.addTarget(self, action: #selector(onRateButton), for: .touchUpInside)
        rateButton.isHidden = false
    }

// .....more

AutoLayout use SnapKit

			self.player.replaceVideo(url)
        view.addSubview(self.player.displayView)
        
        self.player.play()
        self.player.backgroundMode = .proceed
        self.player.delegate = self
        self.player.displayView.delegate = self
        self.player.displayView.titleLabel.text = "China NO.1"
        self.player.displayView.snp.makeConstraints { [weak self] (make) in
            guard let strongSelf = self else { return }
            make.top.left.right.equalToSuperview()
            make.height.equalTo(strongSelf.view.snp.width).multipliedBy(3.0/4.0) // you can 9.0/16.0
        }

Media Cache (Reference: VIMediaCache)

  • VGPlayer Cache Reference VIMediaCache implementation.

  • AVAssetResourceLoader to control AVPlayer download media data.

  • Cache usage range request data, you can cancel the download, fragment cache

  • If you use Simulator debugging, you can view the VGPlayer cache file in the Simulator cache test

  • Usage:

// Settings maxCacheSize
VGPlayerCacheManager.shared.cacheConfig.maxCacheSize = 160000000

// Setting maxCacheAge   default one weak
VGPlayerCacheManager.shared.cacheConfig.maxCacheAge = 60 * 60 * 24 * 7

// clean all cache
VGPlayerCacheManager.shared.cleanAllCache()

// clean old disk cache. 
// This is an async operation.
VGPlayerCacheManager.shared.cleanOldFiles { }

Background playback

  • Project setting

backgroundModes

  • AppDelegate settings
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        do
        {
            try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        }
        catch let error as NSError
        {
            print(error)
        }
        return true
    }
  • VGPlayer Background playback mode to proceed
self.player.backgroundMode = .proceed

Delegate methods optional

// player delegate
    // play state
    func vgPlayer(_ player: VGPlayer, stateDidChange state: VGPlayerState)
    // playe Duration
    func vgPlayer(_ player: VGPlayer, playerDurationDidChange currentDuration: TimeInterval, totalDuration: TimeInterval)
    // buffer state
    func vgPlayer(_ player: VGPlayer, bufferStateDidChange state: VGPlayerBufferstate)
    // buffered Duration
    func vgPlayer(_ player: VGPlayer, bufferedDidChange bufferedDuration: TimeInterval, totalDuration: TimeInterval)
    // play error
    func vgPlayer(_ player: VGPlayer, playerFailed error: VGPlayerError)
    
    
// player view delegate
    /// fullscreen
    func vgPlayerView(_ playerView: VGPlayerView, willFullscreen fullscreen: Bool)
    /// close play view
    func vgPlayerView(didTappedClose playerView: VGPlayerView)
    /// displaye control
    func vgPlayerView(didDisplayControl playerView: VGPlayerView)
    

Installation

  • Download VGPlayer. Move to your project.

Cocoapods

Swift 4

use_frameworks!
pod 'VGPlayer', '~> 0.2.0'

Swift 3

use_frameworks!
pod 'VGPlayer', '~> 0.1.5'

Carthage

github "VeinGuo/VGPlayer"

Run carthage update. to build the framework and drag the built VGPlayer.framework and SnapKit.framework into your Xcode project.

Reference

License

MIT

Comments
  • Error in originalURL

    Error in originalURL

    I always get an error in originalURL "fatal error: unexpectedly found nil while unwrapping an Optional value" I debug code many times. I pass URL value to replaceVideo function but it didn't play my video. application crashes and gives me an error that I mentioned previously. I attached screenshot so you can understand my problem better and give me appropriate solution. screen shot 2017-07-15 at 9 10 32 pm

    bug 
    opened by rehannali 15
  • Changing timeout value for VGPlayer

    Changing timeout value for VGPlayer

    Hi We are using VGPlayer in our application but some of our users constantly report they cannot see the video. When we investigate their log files it seems that VGPlayer says "request timed out" We also encountered the same problem, while we have poor internet connection.

    But we couldnt find where to change the timeout parameter. Can you point us to the right direction? Thanks

    opened by tolgatanriverdi 6
  • Cache manager

    Cache manager

    @VeinGuo I'm going to implement offline video feature in app. I found that the library VGPlayer caches the video automatically. So here are some questions about video caching in this library.

    1. Is there any way to find the cache file path for the specific url in VGPlayer?
    2. Is there any option to enable/disable caching for the video in the library?
    3. I'm going to give the user an option to download the video. To make this logic compatible with your cache manager, I think it's good to download the video directly to the cache directory. Does your cache manager simply saves the video after download is completed? What happens if user close the app before the cache manager completes downloading?
    4. I'm looking for the solution to manually download the specific video file to the cache rather than cache manager automatically does. Is it possible?

    It would be helpful for me if you explain about how your cache manager is working. Any response is appreciated.

    Thanks!

    opened by kennybuc 4
  • Disk cache and memory cache

    Disk cache and memory cache

    @VeinGuo

    Hello, I'm writing here in order to let you know that I'm experiencing some problems with video playing in iOS 9. (iOS 9.3.5 actually) When I choose to play, it just shows black screen. No spinning circle. When I select play button, nothing happens. In debug window, I found the following logcat. Not sure if it was from this library.

    Communications error: <OS_xpc_error: <error: 0x1075c7b40> { count = 1, contents =
    "XPCErrorDescription" => <string: 0x1075c7ef0> { length = 22, contents = "Connection interrupted" }
    

    }>

    And sometimes the video has started but stopped in the middle. For example, it stopped at 00:11. It's supposed to show spinning circle if it's buffering but it doesn't show. The issue happened on my iPad which has installed iOS 9.3.5. I've tried on iOS 9.3 simulator and found the same issue. It happens barely on simulator than iPad.

    So there are two issues

    • Video does not start at all with black screen
    • Video started but stops in the middle.

    I'm wondering if this is related with cache. Here are some questions.

    • What is the difference between following methods? VGPlayerCacheManager.shared.cleanAllCache() VGPlayerCacheManager.shared.cleanOldFiles I'm sorry for this question but I don't have got deep understanding about cache management in iOS. I guess these methods are related with memory cache and disk cache but I don't know exactly.

    If video playing issue is related with cache management, what should I do to properly manage caches?

    I appreciate your patience for reading my report. Please let me know if you have got some explanations.

    Thanks!

    opened by kennybuc 3
  • What kind of URL to play?

    What kind of URL to play?

    Hi VeinGuo, Thanks for this wonderful library. I just wonder what kind of url i can pass into the view? cause i tried the one in dropbox and seems like it is not working, So i am unsure what happen if i get from Azure storage for example. Would that still be ok? I am still new to this stuffs so i am not too sure what to ask. If my words are not really understandable, i will explain more.

    opened by heuism 3
  • Disable certain pan gestures

    Disable certain pan gestures

    It would be nice to have the possibility to control whether you want the user to change the volume and brightness of the screen with a pan gesture or not.

    enhancement 
    opened by mittenimraum 3
  • Add back Button to ads View

    Add back Button to ads View

    Hey, I'm trying to add another button in top corner right end so it can also be used for the back button. I tried to insert it and add constraints but the button is not showing up. I attached changing in your code so you know what I changed or what I need to do to work it. Thanks

    screen shot 2017-08-03 at 5 02 37 pm screen shot 2017-08-03 at 5 02 57 pm screen shot 2017-08-03 at 5 03 05 pm
    opened by rehannali 3
  • Issue: There is no sound some times

    Issue: There is no sound some times

    Hello thank you so much for nice plugin. There is small issue on sound when videos is playing no sound.

    It would be great it it will be fixed. I am going to upload my app soon. I can not wait But it would be great if you can help fix this issue

    thank you

    opened by kristoff2016 2
  • Paste board doesn't work.

    Paste board doesn't work.

    I am using "PHFComposeBarView" a third party liberary in my chat app, but after integrating this in my app. my compose bar doesn't responding paste options. Only compose bar didn't works fine but in other screens in textview or textfield paste board working. Please suggest me how would I fix this.

    opened by PCGurjar 2
  • Media Caching

    Media Caching

    I see that media caching might be on the roadmap. I'm curious what approach you might have in mind, as I might be able to contribute with a pull request.

    opened by waltermvp 2
  • FullScreen not possible

    FullScreen not possible

    Hi! I can't get the player to full screen. Any ideas? The example app is working, but once copied your exampel code 1:1 into my application it just not going into orientation:landscaperight. Any ideas?

    opened by Sub-Zero-1 1
  • Full screen in portrait App

    Full screen in portrait App

    Hi First,thnak to you for good library my app is working in portrait mode(i can not enable landscapeLeft or landscaperight ),whene i select full screen button,nothing happens

    plz help thnaks

    opened by amirch123 1
  • How to stop animation when adding default display view in playerview

    How to stop animation when adding default display view in playerview

    When the default player view is being added to the player view, it show a strange animation while adding. How to remove this animation. The code for adding view is: self.displayView.snp.makeConstraints {(make) in make.top.equalTo(view.snp.top) make.left.equalTo(view.snp.left) make.right.equalTo(view.snp.right) make.bottom.equalTo(view.snp.bottom) }

    opened by userSV 0
  • Video is not playing

    Video is not playing

    Video URL : "http://edge.linknetott.swiftserve.com/live/BsNew/amlst:bsnew/playlist.m3u8"

    when i am trying to play video got this type of error :

    error: Optional(Error Domain=CoreMediaErrorDomain Code=-12881 "custom url not redirect" (See -[AVPlayerItem errorLog] for 3 events) UserInfo={NSDescription=custom url not redirect, NSDebugDescription=See -[AVPlayerItem errorLog] for 3 events}) playerItemErrorLogEvent: Optional([<AVPlayerItemErrorLogEvent: 0x1c00152b0>, <AVPlayerItemErrorLogEvent: 0x1c0015930>, <AVPlayerItemErrorLogEvent: 0x1c0015960>]) extendedLogData: Optional(897 bytes) extendedLogDataStringEncoding Optional(4)

    send me mail if anyone found the solution : [email protected] .... Thanks in advance

    opened by Rudra2511 0
Releases(0.2.0)
Owner
Wen Rong
Noob iOS/macOS Developer.
Wen Rong
▶️ 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
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
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
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
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
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
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
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
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
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
📽 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
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
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
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
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
A fully functional short video app project.Record a six secends video while playing prank sounds.

prankPro A fully functional short video app project How to Install 1. use coconapod to init your xcode environment. 2. change the app-keys in `applica

huijimuhe 258 Jun 19, 2022