Giter VIP home page Giter VIP logo

jpvideoplayer's Introduction

license pod pod pod

This library provides an video player with cache support in UITableView base on AVPlayer.

Note

This project has abandoned due to personal reason.

由于日常工作比较忙,没有精力继续维护该项目,抱歉。

Features

  • Cache video data at playing.
  • Seek time support(new).
  • Breakpoint continuingly support(new).
  • Landscape auto-layout support(new).
  • Custom player controlView support(new).
  • Excellent performance!
  • A guarantee that the same URL won't be downloaded several times
  • A guarantee that main thread will never be blocked
  • Location video play support
  • Swift support

Requirements

  • iOS 8.0 or later
  • Xcode 7.3 or later

Getting Started

How To Use

01.Play video.

1.1.Mute play video and display progressView on UITableViewCell or any view.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_playVideoMuteWithURL:url
            bufferingIndicator:nil
                  progressView:nil
           	 configuration:nil];

1.2.Resume mute play from UITableViewController to a detail UIViewControllerwhen user selected a UITableViewCell.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_resumeMutePlayWithURL:url
             bufferingIndicator:nil
                   progressView:nil
        	  configuration:nil];

1.3.Play video and display controlView & progressView.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_playVideoWithURL:url
        bufferingIndicator:nil
               controlView:nil
              progressView:nil
   	     configuration:nil];

1.4.Resume play with displaying controlView & progressView.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_resumePlayWithURL:url
         bufferingIndicator:nil
                controlView:nil
               progressView:nil
    	      configuration:nil];

1.5.Play video without controlView & progressView.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_playVideoWithURL:url
		   options:kNilOptions
   	     configuration:nil];

1.6. Resume play without controlView & progressView.

NSURL *url = [NSURL URLWithString:@"http://p11s9kqxf.bkt.clouddn.com/bianche.mp4"];
[aview jp_resumePlayWithURL:url
		    options:kNilOptions
    	      configuration:nil];

2.Landscape Or Portrait Control

2.1. Go to landscape.

[aview jp_gotoLandscape];

[aview jp_gotoLandscapeAnimated:YES completion:nil];

2.2. Go to portrait.

[aview jp_gotoPortrait];

[aview jp_gotoPortraitAnimated:YES completion:nil];

3. Play video in UITableView like Weibo.

Play video in UITableView support equal height and un-eqaul height cell now, you can use a category method on UITableView directly. You also should set the jp_tableViewVisibleFrame accurately to insure playing video on the cell that closest to the center of the screen.

[tableView jp_playVideoInVisibleCellsIfNeed];

[tableView jp_handleCellUnreachableTypeInVisibleCellsAfterReloadData];

[tableView jp_handleCellUnreachableTypeForCell:cell
                                   atIndexPath:indexPath];

[tableView jp_scrollViewDidScroll];

[tableView jp_scrollViewDidEndDraggingWillDecelerate:decelerate];

[tableView jp_scrollViewDidEndDecelerating];

4. Custom controlView & progressView & bufferingIndicator.

This library offered a basic JPVideoPlayerProgressViewJPVideoPlayerBufferingIndicatorJPVideoPlayerControlView, so you can pass nil in play video method. You can inherit those basic class to custom your own UI, and you also can not inherit it, directly use your own UI, but you must implete the method in JPVideoPlayerControlProgressProtocolJPVideoPlayerBufferingProtocolJPVideoPlayerProtocol.

5. Cache manage.

[JPVideoPlayerCache.sharedCache calculateSizeOnCompletion:^(NSUInteger fileCount, NSUInteger totalSize) {
    // do something.
}];

[JPVideoPlayerCache.sharedCache clearDiskOnCompletion:^{
    // do something
}];

Installation

There are two ways to use JPVideoPlayer in your project:

  • using CocoaPods
  • by cloning the project into your repository

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

platform :ios, '8.0'
target "YourProjectName" do
pod 'JPVideoPlayer'
end

Communication

  • If you found a bug, open an issue please.
  • If you have a feature request, open an issue please.
  • If you want to contribute, submit a pull request please.

Licenses

All source code is licensed under the MIT License.

Architecture

jpvideoplayer's People

Contributors

audrl1010 avatar chris-pan avatar dito010 avatar memetghini avatar riveryan avatar smhjsw 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jpvideoplayer's Issues

播放完成定制

目前播放完成后默认是seek到0,个人建议播放完成应该给一个回调,让开发者可以自定义播放完成的后续行为,这样的话定制性更强

并没有播放屏幕中间的Cell内的视频, 播放的是屏幕最下边的.....

并没有在tableviewcontroller里做特殊处理, 只是在cell的loadData方法里直接调用了Readme里的使用方法

class SocialVideoTableViewCell: SocialBaseTableViewCell {
    @IBOutlet weak var videoView: UIView!
    let player = JPVideoPlayer.sharedInstance()
    

    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func loadData(message: SocialItem) {
        super.loadData(message: message)
        player?.play(with: URL(string: message.video), show: videoView)
    }
}

1

部分视频不支持边下边播

手势滑动返回过程中,播放变的卡顿?

目录结构为Nav->vc1->vc2 当player在vc2中,手势滑动返回至vc1的过程中,player会播放卡顿!!!
手势返回的过程中,就是vc2慢慢的手势返回到vc1但始终没放手没有完全的pop回去,手势来回左右滑动,在这个过程中,player会变的卡顿。但是我看bilibili和今日头条等app ,在此过程都没有出现这个问题,项目中又用到这一块,所以想查明原因。但下了很多封装avplayer的demo 发现都有此问题(当然也试了您写的JPVideoPlayer)。

播放七牛云视频总失败

https:/videossl.edujia.com/team/video/6oley/seq/A7FE2CB3-BF1F-47CA-8843-BB56C63D6A54.mp4

这个链接,总是失败,但是在浏览器打开是没有问题的

无后缀音频无法播放

修改demo中的播放列表.
self.pathStrings = @[
@"http://tts.baidu.com/text2audio?idx=1&cuid=baidu_speech_demo&cod=2&lan=zh&ctp=1&pdt=1&spd=5&per=2&vol=5&pit=5&tex=you",
@"http://tts.baidu.com/text2audio?idx=1&cuid=baidu_speech_demo&cod=2&lan=zh&ctp=1&pdt=1&spd=5&per=2&vol=5&pit=5&tex=baidu",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=users",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=download",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=controller",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=view",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=model",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=video",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=distant",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=only",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=things",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=were",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=universal",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=stare",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=made",
@"http://tts.baidu.com/text2audio?lan=en&pid=101&ie=UTF-8&spd=3&text=but",
];
貌似没有后缀就无法播放, 不知道应该怎么处理, 正常使用avplayer可以.
在status的kvo打印error为:

Error Domain=AVFoundationErrorDomain Code=-11828 "Cannot Open" UserInfo={NSUnderlyingError=0x174054dc0 {Error Domain=NSOSStatusErrorDomain Code=-12847 "(null)"}, NSLocalizedFailureReason=This media format is not supported., NSLocalizedDescription=Cannot Open}

刷新对应的cell视频会卡

在点击cell的方法中
加[self.tableView reloadData];不会卡--作者此版本已经解决了。
但是加[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];会停止播放,显示占位图。

几个小建议

  1. UIView+PlayerStatusAndDownloadIndicator 中,像 progressView 这种比较大众化的属性,是否可以加个前缀(jp_progressView)?😂

  2. 是否可以加入,暂停和续播的功能(只是暂停),包括获取播放状态,场景是正在播放视频,模态出一个界面这个时候暂停播放,界面消失后继续播放。如果调用目前工程中的stop后,其实是移除了item和取消下载。

  3. 是否能加入一个新功能,可以设置预加载时间,比如播放视频的时候,当下载的视频达到可播放10s,才播放。

Can not play video from URl with local path.

@newyjp hi, thanks for sharing code!
Is it possible to play video from local path, like this

file:///Users/user/Library/Developer/CoreSimulator/Devices/5D5434B8-71C9-41C3-9038-1CFB387C8F43/data/Containers/Data/Application/C4F6B123-4372-4B71-A87B-EB59ABA6FA77/Library/Caches/4487/a417/e7fd/0331/34b3/edf3/1a85/9437/4487a417e7fd033134b3edf31a859437cfd6744d74374f474be69affa1a19432

like this one

let documentsURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]
let fileURL = documentsURL.appendingPathComponent("localPath")
            
if FileManager.default.fileExists(atPath: fileURL.path) {
               print("FileManager.default.fileExists")
               cellImageView.jp_playVideo(with: fileURL)

}

I have tried to play video, but still no sucess

进度条问题

视频不能快进和后退希望大神能够完善这个需求

Can I Use this CollectionView

Hey I have a doubt, In my current project I want to achieve something like Instagram feed autoplay the videos with no volume and by using collectionViews
does your framework allow me to build this functionality??
thank you

预缓存

怎样播放视频的时候下载一个准备播放的视频

视频播放缓冲黑屏问题

在视频缓冲是,背景颜色是黑色,建议改成透明。因为我需要在缓冲的时候显示第一帧的图像并且根据下载的进度进行缓慢加载的动画。
我已经手动修改 jp_backgroundLayer 的 backgroundColor为透明
希望下一个版本可以自定义颜色,或者允许用户自定义一个 placeholderImage(只需要在jp_backgroundLayer下面加一层UIViewImageView即可实现)

第二次播放同一视频时不能播放

正好我最近在做tableview的自动播放,问题是这样的:我们公司视频也是放在七牛上,做了cdn加速,这些视频在浏览器上和安卓上放都没有问题,用你这个框架放的时候当同一视频第二次播放的时候(不论是我来回滑动tableVIew,还是我杀了app重进项目),这个视频就不能播放了。我把我们的视频地址替换掉了你在demo中的地址后也是如此,所以我认为是你对缓存的判断上出了问题(后来我手动清除缓存确实能解决上述问题)。抱歉最近工作比较忙,不能帮助解决问题,希望近期能做出修改,同时也希望jpplayer能越做越好。附上我们测试的视频地址,希望对你有帮助:
self.pathStrings = @[
@"http://user.xiaomatv.cn/Foc5W0gIy8tjfMzrqB_Gn1zqpL2o",
@"http://user.xiaomatv.cn/FovHs997_HNgLsYojH0SiPTUd6T7",
@"http://user.xiaomatv.cn/FihpcBVbzxZF687Nf2FEuJjaVGS-",
@"http://user.xiaomatv.cn/FpCndpLOATECqfFHXd_VYKl268Pz",
@"http://user.xiaomatv.cn/lmNrTlHdjrxDJclcFs3O5tfFmhYW",
@"http://user.xiaomatv.cn/FsDEg7qDSxwTQy_E5YyVEdmXYmmX",
@"http://user.xiaomatv.cn/FnjwGdu_hy4W-4mie41XT0ssjNAj",
@"http://user.xiaomatv.cn/FhRw_KdZlqitbrZOQYNcv62Slzet"

调整播放进度

简书文章中有提到拖拽的问题,这里好像没有调整播放进度的API, 这个没实现吗?

能否支持预加载

在当前视频加载时,预先加载下一个Index的视频,当用户滑动到下一个视频时可以立即开始播放

无法显示进度条

现在只有下载的进度条,我如果需要显示播放的进度条该如何设置?
本来想要自己用NSTimer 来显示,发现你的AVPlayer 和 AVURLAsset 设为了私有变量,并没有开发出来。希望你能有好的方法解决掉这个问题。
我暂时在项目中修改了你的这部分代码,希望下一个版本你能把这个功能添加进去。

关于indicatorView的两个bug。

else if ([keyPath isEqualToString:@"playbackBufferEmpty"]){ [self showActivaityIndicatorView]; } else if ([keyPath isEqualToString:@"playbackLikelyToKeepUp"]){ [self hideActivaityIndicatorView]; }

这个地方有点问题。一个是playbackLikelyToKeepUp这个是个BOOL值,observer如果检测到为值变为NO,那么showIndicatorView是没问题的,如果是YES呢?这里没有判断。
第二个是用playbackLikelyToKeepUp来判断是否显示IndicatorView不准确。我用几个视频测试了一下。发现有2-3秒的延迟。这个值得注释也说了,“In this event the playback buffer has
reached capacity but there isn't the statistical data to support a prediction that playback is likely to
keep up”
只是表明buffer有了,但不代表立即可以播放。
目前来看最准确的检测什么时候隐藏和显示IndicatorView的还是observe player的rate。
如果不是用户暂停的情况下,rate == 0肯定表示加载中,>0表示正在播放,那肯定代表已经加载完成了。

现在播放器的功能有点弱。我觉得可以加入快进快退(scrub)的功能,和进度的delegate。
缓存是写的确实很好。

很不错

不错, 很喜欢. 自己研究下

UIViewController+Landscape.h +(void)load

当用户继承并重写了UIViewController子类的load方法,并且调用了[super load]方法时,会导致你重写的load方法调用多次。
由于你在类别里面重写了load方法并且调用了[super load],你应该对load方法做如下修改或者取消调用 [super load]

+(void)load{
    [super load];
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        [self jr_swizzleMethod:@selector(viewDidLoad) withMethod:@selector(jp_viewDidLoad) error:nil];
        [self jr_swizzleMethod:NSSelectorFromString(@"dealloc") withMethod:@selector(jp_dealloc) error:nil];
        [self jr_swizzleMethod:@selector(shouldAutorotate) withMethod:@selector(jp_shouldAutorotate) error:nil];
    });
}

后台切换回来视频会自动播放

我已经把JPVideoPlayerPlayVideoTool中becomeAvtive的通知去掉了,在外部控制暂停播放。
但是在暂停状态下,后台切换几次有时会自动播放,持续在前台切到其他界面,视频播放器的状态是暂停,有时候也会自动播放

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.