BMPlayer - A video player for iOS, based on AVPlayer, support the horizontal, vertical screen

Overview

BMPlayer

Swift 2.2-5.0 Carthage compatible Version License Platform Weibo FOSSA Status

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

中文说明

Features

  • Support for horizontal and vertical play mode
  • Support play online URL and local file
  • Adjust brightness by slide vertical at left side of screen
  • Adjust volume by slide vertical at right side of screen
  • Slide horizontal to fast forward and rewind
  • Support multi-definition video
  • Custom playrate
  • Add Http header and other options to AVURLAsset
  • Easy to customize
  • Supporting show local and online subtitles
  • Swift 5

Requirements

  • iOS 10.0+
  • Xcode 10.0+
  • Swift 4+

Supporting the project

You can support the project by checking out our sponsor page. It takes only one click:

Sponsor banner
This advert was placed by GitAds

Installation

CocoaPods

Swift podfile
Swift 5.0 pod 'BMPlayer', '~> 1.3.0'
Swift 4.2 pod 'BMPlayer', '~> 1.2.0'
Swift 4.0 pod 'BMPlayer', '~> 1.0.0'
Swift 3.0 pod 'BMPlayer', '~> 0.9.1'
Swift 2.2 pod 'BMPlayer', '~> 0.3.3'

To test the experimental caching support with VIMediaCache, use

pod 'BMPlayer/CacheSupport', :git => 'https://github.com/BrikerMan/BMPlayer.git'

Carthage

Add BMPlayer in your Cartfile.

github "BrikerMan/BMPlayer"

Run carthage to build the framework and drag the built BMPlayer.framework into your Xcode project.

Demo

run pod install at Example folder before run the demo.

Usage (Support IB and code)

Set status bar color

Please add the View controller-based status bar appearance field in info.plist and change it to NO

IB usage

Direct drag IB to UIView, the aspect ratio for the 16:9 constraint (priority to 750, lower than the 1000 line), the code section only needs to achieve. See more detail on the demo.

import BMPlayer

player.playWithURL(URL(string: url)!)

player.backBlock = { [unowned self] (isFullScreen) in
    if isFullScreen == true { return }
    let _ = self.navigationController?.popViewController(animated: true)
}

Code implementation by SnapKit

import BMPlayer

player = BMPlayer()
view.addSubview(player)
player.snp.makeConstraints { (make) in
    make.top.equalTo(self.view).offset(20)
    make.left.right.equalTo(self.view)
    // Note here, the aspect ratio 16:9 priority is lower than 1000 on the line, because the 4S iPhone aspect ratio is not 16:9
    make.height.equalTo(player.snp.width).multipliedBy(9.0/16.0).priority(750)
}
// Back button event
player.backBlock = { [unowned self] (isFullScreen) in
    if isFullScreen == true { return }
    let _ = self.navigationController?.popViewController(animated: true)
}

Set video url

let asset = BMPlayerResource(url: URL(string: "http://baobab.wdjcdn.com/14525705791193.mp4")!,
                             name: "风格互换:原来你我相爱")
player.setVideo(resource: asset)

multi-definition video with cover

let res0 = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                      definition: "高清")
let res1 = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                      definition: "标清")

let asset = BMPlayerResource(name: "周末号外丨中国第一高楼",
                             definitions: [res0, res1],
                             cover: URL(string: "http://img.wdjimg.com/image/video/447f973848167ee5e44b67c8d4df9839_0_0.jpeg"))

player.setVideo(resource: asset)

Add HTTP header for request

let header = ["User-Agent":"BMPlayer"]
let options = ["AVURLAssetHTTPHeaderFieldsKey":header]

let definition = BMPlayerResourceDefinition(url: URL(string: "http://baobab.wdjcdn.com/1457162012752491010143.mp4")!,
                                            definition: "高清",
                                            options: options)

let asset = BMPlayerResource(name: "Video Name",
                             definitions: [definition])

Listening to player state changes

See more detail from the Example project

Block

//Listen to when the player is playing or stopped
player?.playStateDidChange = { (isPlaying: Bool) in
    print("playStateDidChange \(isPlaying)")
}

//Listen to when the play time changes
player?.playTimeDidChange = { (currentTime: TimeInterval, totalTime: TimeInterval) in
    print("playTimeDidChange currentTime: \(currentTime) totalTime: \(totalTime)")
}

Delegate

protocol BMPlayerDelegate {
    func bmPlayer(player: BMPlayer ,playerStateDidChange state: BMPlayerState) { }
    func bmPlayer(player: BMPlayer ,loadedTimeDidChange loadedDuration: TimeInterval, totalDuration: TimeInterval)  { }
    func bmPlayer(player: BMPlayer ,playTimeDidChange currentTime : TimeInterval, totalTime: TimeInterval)  { }
    func bmPlayer(player: BMPlayer ,playerIsPlaying playing: Bool)  { }
}

Customize player

Needs to change before the player alloc.

// should print log, default false
BMPlayerConf.allowLog = false
// should auto play, default true
BMPlayerConf.shouldAutoPlay = true
// main tint color, default whiteColor
BMPlayerConf.tintColor = UIColor.whiteColor()
// options to show header view (which include the back button, title and definition change button) , default .Always,options: .Always, .HorizantalOnly and .None
BMPlayerConf.topBarShowInCase = .Always
// loader type, see detail:https://github.com/ninjaprox/NVActivityIndicatorView
BMPlayerConf.loaderType  = NVActivityIndicatorType.BallRotateChase
// enable setting the brightness by touch gesture in the player
BMPlayerConf.enableBrightnessGestures = true
// enable setting the volume by touch gesture in the player
BMPlayerConf.enableVolumeGestures = true
// enable setting the playtime by touch gesture in the player
BMPlayerConf.enablePlaytimeGestures = true

Advanced Customize

  • Subclass BMPlayerControlView to create your personal control UI, check the Example.
  • Use the BMPlayerLayer with your own player control view.

Demonstration

gif

Reference:

This project heavily reference the Objective-C version of this project ZFPlayer, thanks for the generous help of ZFPlayer's author.

Contact me:

Contributors

You are welcome to fork and submit pull requests.

License

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

FOSSA Status

Comments
  • Subtitles

    Subtitles

    Hi,

    I have implemented Bmplayer and its perfect for my app requirements. But i need to implement more features like subtitles, is there any way to show subtitles of video on Bmplayer.

    Thanks for help

    Waiting for feedback 
    opened by AdeelNoor17 21
  • Player loads when subtitle change

    Player loads when subtitle change

    Hi All,

    Thank you for providing this wonderful library.

    There is an issue or behavior I must say which I marked is player load itself when we change the subtitle. Is there a way we just can change the subtitle without changing the video url. Currently while changing subtitle, we are using the below code

            let str = URL(string: "new subtitle url")
            
            let url =  URL(string: "current video url")!
            
            let subtitle = BMSubtitles(url: str)
            
            let asset = BMPlayerResource(name: "Video Name Here",
                                         definitions: [BMPlayerResourceDefinition(url: url, definition: "")],
                                         cover: nil,
                                         subtitles: subtitle)
            
            
            player.setVideo(resource: asset)
    

    This is loading the video and it seems like, its changing the track. Could you please help us on this.

    opened by DipyaChandniDas 14
  • Discussion: An easy way to customize control UI

    Discussion: An easy way to customize control UI

    I created BMPlayerCustomControlView to allow users to customize UI easily, but it makes thing worse. I am planning to refactor the whole player to allow the user easily customize the control UI. There are several ideas:

    1. create a BMPlayerControlView and allow the user to subclass and change the Auto-layout and icon images to customize UI.
    2. use the BMPlayerCustomControlView to customize and simplify the protocol.
    Waiting for feedback 
    opened by BrikerMan 13
  • Manual control loading indictator

    Manual control loading indictator

    Please tell me how to control loadingIndector manually

    I'm using BMPlayer. But loadingIndicator always showing. So, in viewdidload function I want to stop it. But i can't do it.

    Waiting for feedback 
    opened by hunghn86 9
  • 切换源crash

    切换源crash

    更新了新版后,切换多个视频源会crash if playerItem!.isPlaybackLikelyToKeepUp || playerItem!.isPlaybackBufferFull { self.state = .bufferFinished } else { self.state = .buffering } 这里不要强制解包playerItem,因为playerItem可能为nil。 另外视频播放完成后,播放按钮会时不时跳到暂停然后恢复,一直循环重复。

    bug Waiting for feedback 
    opened by jihongboo 9
  • No Such Module for NVActivityIndicatorView and BMPlayer

    No Such Module for NVActivityIndicatorView and BMPlayer

    Hello, after download the latest version of your project i run pod install located in BMPlayer-master/Example . It run correctly without errors but when I open the example project the build fail because xcode doesn't fine the two module that I described in the issue object. I used the last version of cocoa pods. Could you help me ? I report some screenshot pod_install1 pod_install2 pod_install3 example project

    opened by xbomber360 8
  • 1. 因为实际需要添加了慢放和镜像的功能, 两个功能的开关可以在播放器管理单例中配置. BMPlayerConf.slowAndMirro…

    1. 因为实际需要添加了慢放和镜像的功能, 两个功能的开关可以在播放器管理单例中配置. BMPlayerConf.slowAndMirro…

    1. 因为实际需要添加了慢放和镜像的功能, 两个功能的开关可以在播放器管理单例中配置. BMPlayerConf.slowAndMirror = true
    2. 在BMPlayer类中添加了一个方法updateUI(Bool), 用于解决手动旋转设备横屏时不能调用到ControlView中的updateUI方法,导致切换清晰度按钮不能更新的问题. 具体的调用方法为在播放Controller中override willTransitionToTraitCollection方法.
    override func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
            super.willTransitionToTraitCollection(newCollection, withTransitionCoordinator: coordinator)
            coordinator.animateAlongsideTransition({
                a in
    
                if (newCollection.verticalSizeClass == UIUserInterfaceSizeClass.Compact) {
                    self.player.updateUI(true)
                } else {
                    self.player.updateUI(false)
                    //To Do: modify something for other vertical size
                }
                self.view.setNeedsLayout()
                }, completion: nil)
    
    
        }
    
    
    opened by cedared 8
  • 无法播放不带视频格式的在线视频

    无法播放不带视频格式的在线视频

    Check List

    Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    Installed with

    • [ ] Carthage
    • [x] Cocoapods

    Issue Description

    比如:https://v.qq.com/iframe/player.html?vid=g0528hi619c 这种格式的视频链接无法播放

    [Tell us about the issue]

    Reproduce

    [The steps to reproduce this issue. What is the URL you were trying to play, where did you put your code, etc.]

    Other Comment

    [Add anything else here]

    opened by xiaomage1478 7
  • Unable to buffer HLS Cached Video in iOS 10 without internet connection.

    Unable to buffer HLS Cached Video in iOS 10 without internet connection.

    I am using AVAsset download delegates to download M3u8 files and play it offline.However on playing offline video it needs internet to sync for buffering document files.if internet is active,within few second it buffers a document files.If the network is not available player gets stuck.Kindly help me to solve this issue.looking for a positive response from you.

    opened by venkateshcontus 7
  • 无法定制UI

    无法定制UI

    Check List

    Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    Installed with

    • [ ] Carthage
    • [ ] Cocoapods

    Issue Description

    What

    [Tell us about the issue]

    Reproduce

    [The steps to reproduce this issue. What is the URL you were trying to play, where did you put your code, etc.]

    Other Comment

    [Add anything else here]

    opened by yuzhi123 5
  • After I update BMPlayer,My video can`t play....

    After I update BMPlayer,My video can`t play....

    After I update BMPlayer,My video can`t play....

    This is log :

    | BMPlayerDelegate | loadedTimeDidChange | 95.9298222222222 of 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 loadedTimeDidChange - 100.573822222222 - 189.010422222222 | BMPlayerDelegate | loadedTimeDidChange | 100.573822222222 of 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 loadedTimeDidChange - 103.360222222222 - 189.010422222222 | BMPlayerDelegate | loadedTimeDidChange | 103.360222222222 of 189.010422222222

    ///the player can not play , but can buffer Buffer video:

    playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222 playTimeDidChange - 0.0 - 189.010422222222

    Waiting for feedback 
    opened by wenlanhuitai 5
  • [Enhancement] Preload video asset upto a time/size

    [Enhancement] Preload video asset upto a time/size

    Check List

    Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    1.3.2

    Installed with

    • [ ] Carthage
    • [x] Cocoapods

    Description

    Can we add preloading of video asset? Considering it one of the top video players used by devs and also one of the updated pods, it would be better to have this feature to make this a versatile player.

    GSPlayer has this feature but it seems it has not been maintained since long.

    opened by aakashsrivastav 0
  • Ios 16.0 cannot play in full screen

    Ios 16.0 cannot play in full screen

    Ios 16.0 cannot play in full screen

    2022-11-08 22:47:22.019162+0800 BMPlayer_Example[13285:5049044] [Orientation] BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:) 2022-11-08 22:47:22.019482+0800 BMPlayer_Example[13285:5049044] [Assert] -[UIApplication setStatusBarOrientation:] and -[UIApplication setStatusBarOrientation:animated:] API have been deprecated on iOS 8.0 and are no-ops on iOS 13.0

    opened by xipeng5 2
  • set rate 无效

    set rate 无效

    Check List

    Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    Installed with

    • [ ] Carthage
    • [ ] Cocoapods

    Issue Description

    What

    [Tell us about the issue]

    Reproduce

    [The steps to reproduce this issue. What is the URL you were trying to play, where did you put your code, etc.]

    Other Comment

    [Add anything else here]

    opened by ChinaKeep 1
  • Video gets paused when move the seek bar

    Video gets paused when move the seek bar

    Check List

    Thanks for considering opening an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    Installed with

    • [x] Cocoapods

    Issue Description

    The user is able to view the video paused when the user moves seek bar forward/backward in the video detail screen

    Note: pause icon is not changed when the video gets paused

    Issue happens when buffering is slow

    What

    [Tell us about the issue]

    Reproduce

    Just move the seek bar. The issue happens when buffering is slow

    Other Comment

    [Add anything else here]

    opened by mohamedrafi-rapid 0
  • Can someone please help to implement PIP player

    Can someone please help to implement PIP player

    Check List

    Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

    BMPlayer version

    1.3.0

    Installed with

    • [x] Cocoapods

    Issue Description

    We need to play an array of videos. When we add the next item of video,in PIP the layer is missing. Somebody, please help me her to resolve this issue.

    What

    We need to play an array of videos. When we add the next item of video,in PIP the layer is missing. Somebody, please help me her to resolve this issue.

    Reproduce

    [The steps to reproduce this issue. What is the URL you were trying to play, where did you put your code, etc.]

    Other Comment

    [Add anything else here]

    opened by mohamedrafi-rapid 0
Releases(1.3.2)
Owner
Eliyar Eziz
AI Specialist, Google ML GDE. Love NLP, Love Python.
Eliyar Eziz
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
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
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
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
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
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
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
An alternative to SwiftUI's VideoPlayer that includes an overlay button that will transition the player to be presented full screen.

The VideoPlayer provided by SwiftUI out of the box is great but it's missing one very important feature: full screen presentation mode. AZVideoPlayer behaves pretty much exactly like VideoPlayer, but adds the button that's provided by AVPlayerViewController to go full screen.

Adam Zarn 6 Dec 25, 2022
VIMVideoPlayer is a simple wrapper around the AVPlayer and AVPlayerLayer classes.

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

Vimeo 280 May 11, 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
▶️ 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
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
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