Giter Site home page Giter Site logo

brikerman / bmplayer Goto Github PK

View Code? Open in Web Editor NEW
1.9K 37.0 409.0 24.6 MB

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

Home Page: https://eliyar.biz

License: MIT License

Ruby 2.09% Swift 97.45% Objective-C 0.46%
swift avplayer video-player carthage ios-swift swift3 swift4 swift5

bmplayer's Introduction

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'

Swift Pakage Manager

 '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

bmplayer's People

Contributors

acenqiu avatar benbahrenburg avatar birdmichael avatar brikerman avatar cedared avatar coderwan avatar duca14036 avatar eyrefree avatar fossabot avatar iblacksun avatar jackyoustra avatar janrenz avatar kimpenlon avatar klaus01 avatar krishnachaitanyaamjuri avatar mangomade avatar mik-chan avatar minseks avatar mokai avatar nukenalin avatar sunnyyoung avatar tooodooo avatar tulakshana 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bmplayer's Issues

切换源crash

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

Video does not play in chunks

I have node Server when provide me video in chunks. i want to play video using BMPlayer but does not play it. How to play ???

pod

pod search BMPlayer
[!] Unable to find a pod with name matching `BMPlayer'

Detecting when a stream connection is lost

Hello dear,
how can I know if a connection is lost in the middle of the stream?
for example, when playing a video, and at certain time point, the devices disconnected.

is there any observer or notification that is known for this purpose in AVPlayer?
thanks in advance.

simulator screen shot feb 27 2017 18 59 18

play方法在player未实例化前调用会崩溃

在使用播放器的时候,假如在播放页面modal到其他页面,这个时候我们会暂停播放器,到dismiss回来后需要继续播放。一般就会把播放和暂停方法写在下面方法。

override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.Default, animated: true)
        player.play()
    }

    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: true)
        player.pause()
    }

但是第一次进入播放页时,player可能还没有调用 playWithURLplayWithPlayerItem 方法,这个时候 play 方法中的 videoItemURL 没有值,就会崩溃。

建议增加播放状态监听回调

就是类似于要做连续播放的话,在播放结束的时候能给个回调,或者播放正常结束,还是用户手动结束,还是其他状态啥的。

Remove some dependencies

Is there a way to make BMPlayer work without some of these dependencies:

Using Reveal-iOS-SDK (1.6.2)
Using SnapKit (0.20.0)
Using SwipeBack (1.1.0)

SwipeBack is obj-c and can mess some gestures. :( I don't see any problem with SnapKit or Reveal although.

重新播放按钮显示异常

1.视频播放结束后出现重播按钮,然后点击隐藏mainMaskView,重播按钮会跟着隐藏,然后点击显示mainMaskView时重播按钮已经没了。
2.视频播放结束后出现重播按钮,然后通过点击左下方的播放按钮来播放,重播按钮还会一直显示在中间

How to detect error link play ?

Hi.
I'm using your library in my project to play video streaming.
How can I detect that wrong link is played ?
I have a list link video, and i want auto play next link if current link is error.
Therefore, i want know when link is error.

Thank you so much.

重装APP后AVPlayer不能播放缓存文件

尽管不是BMPlayer的问题,但还是想请教下~

把视频下载到Cache文件夹中缓存,然后播放,其它情况都是正常的,唯独APP重新安装后(覆盖安装)就播放不出来了,文件也还在,AVPlayer只进入ReadToPlay,调用play也不播放,duration也拿不到

Override action of topBar.

Swift 2.2 - release v0.3.3

In full screen mode, when I tap the topbar, I'd like to return to the root controller instead of going to portrait mode.

I know if I set self.navigationController?.popToRootViewControllerAnimated(true), I will be sent to the root view when I tap the navigation Back button. I wonder if there's something similar to the topbar.

Or maybe should I override or rewrite some method? Suggestions?

Thanks in advance!

怎样设置user-agent??

怎样设置user-agent??,有些服务器设置了这个参数,不知怎样设置。求助,谢谢。

视频播放完毕重播的BUG

视频播完后会出现重播按钮,不通过重播按钮来重播的步骤:

1.按空白处隐藏重播按钮
2.再次点击出现控制条,此时重播按钮已消失
3.点击下方三角播放按钮无法播放
4.拖动进度条可以进行播放,播放按钮的状态不正确,有时状态进度条的进度也不正确

How to Disable Volume/Brightness controls

Hi, I am including your video Player in a tableviewcell. It works great however, when i want to scroll down and by accident scroll on the video it changes the volume and sometimes the brightness. How can I disable this? Thanks!

播放时的一个Bug

你好很高兴你能开源这个库。最近我也在使用它。发现了一个小小的bug

在设置了player.playWithURL()之后,视频会自动的播放,但是呢播放按钮呢并不是暂停的按钮而是播放按钮。

qq20160518-1

用于cell的player

我们的主播放器使用了你的项目,现在运行的情况非常好。
现在我们需要在一个tableview上使用播放器,目前的播放器UI对我们来说太复杂了,并且我尝试禁用panGesture但是无效。
能否提供隐藏UI和禁用panGesture的方法?

视频比例不是16:9的时候出现bug

我做的是手机屏幕录制,录出来的视频横屏的时候就会出现一半的效果,你的约束应该是对于设置的size中心对齐,宽高以最大的那个缩放,oc的项目也有这个问题。

Full screen issue

When i full screen the player the view doesn't come full screen and the controls for slow motion are not seen.

强制点击播放按钮崩溃

受限于网络原因,播放器UI已经加载完毕的情况下播放地址还没有获取到,此时强制点击播放按钮会崩溃
fileprivate func configPlayer(){
self.playerItem = AVPlayerItem(url: videoURL)
}
很明显此时videoURL为nil。
建议此处加一个判断。

更新后出现异常

player.backBlock = { [unowned self] in
self.navigationController?.popViewControllerAnimated(true)
}

更新后出现异常, type() -> type() , type(Bool) -> void

turn off volume

So I want to initially begin autoplaying the video with volume set to 0.
How do I do this?

I have been using self.videoView..reduceVolume()
but that mutes the entire phone. I want the initial volume of ONLY the video to be 0. Then when the video is tapped to bring it up to say 50%.

Is this possible?

Thanks in advance

iPhone5s View have a bug

qq20160526-0

        player.snp_makeConstraints { (make) in
            make.trailing.leading.equalTo(self.view)
            make.top.equalTo(self.view)
            make.height.equalTo(self.view.snp_width).multipliedBy(9.0 / 16.0).priority(750)
        }

iPhone5s 上横屏的时候并没有满屏,在iPhone6 or iPhone6P 没有这个问题

建议不要去掉全屏下返回按钮的回调

读了你的源码,全屏模式下,返回按钮的回调去掉了,可能是为了简化操作逻辑,避免返回事件同时应用到两种播放器状态下。但对于某些页面就单独一个全屏播放器而言,返回按钮可能还要处理其他事件(比如pop vc等)。因此建议backblock可以全模式使用,并且最好能把isFullScreen参数传过来,方便区分。

建议

提个建议, 建议把controlview中的相关组件的权限设置为public 以便于用户可以自定义播放器样式

Manual seeking

How would I start playing a video from a certain position? In AVFoundation this is done with seekToTime

playTimeDidChange

Hi
I need change time "playTimeDidChange" to millisecond from second.
please help me.

BMPlayer not playing video is slide the tracker

if i press play button video doesnt get played. If I write bmPlayer.play() and call that function then it is player else bmPlayer doesnot play.
Version used :
pod 'BMPlayer', '~> 0.3.3'

Issue in landscape(full screen) in iPad

Hi ,

Thanks for this good library. I tried this iPhones and its working good but in iPad, in Full screen or landscape, its not covering the full screen. Please help me.

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.