init
This commit is contained in:
18
Example/SellyCloudSDK/Play/SCPlayItemContainerView.h
Normal file
18
Example/SellyCloudSDK/Play/SCPlayItemContainerView.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// SCLiveItemContainerView.h
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "SCPlayItemModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SCPlayItemContainerView : UIView
|
||||
@property (nonatomic, strong)NSArray<SCPlayItemModel *> *models;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
57
Example/SellyCloudSDK/Play/SCPlayItemContainerView.m
Normal file
57
Example/SellyCloudSDK/Play/SCPlayItemContainerView.m
Normal file
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// SCLiveItemContainerView.m
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SCPlayItemContainerView.h"
|
||||
#import "SCPlayItemView.h"
|
||||
|
||||
@interface SCPlayItemContainerView ()
|
||||
@property (nonatomic, strong)NSMutableArray<SCPlayItemView *> *itemViews;
|
||||
@end
|
||||
|
||||
@implementation SCPlayItemContainerView
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.backgroundColor = UIColor.cyanColor;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setModels:(NSArray<SCPlayItemModel *> *)models {
|
||||
_models = models;
|
||||
|
||||
[self.itemViews enumerateObjectsUsingBlock:^(SCPlayItemView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
[obj removeFromSuperview];
|
||||
}];
|
||||
[self.itemViews removeAllObjects];
|
||||
|
||||
for (NSInteger i = 0; i<models.count; i++) {
|
||||
SCPlayItemView *itemView = SCPlayItemView.new;
|
||||
itemView.model = models[i];
|
||||
[self.itemViews addObject:itemView];
|
||||
[self addSubview:itemView];
|
||||
}
|
||||
|
||||
[self.itemViews mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:100 leadSpacing:15 tailSpacing:15];
|
||||
[self.itemViews mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.height.offset(80);
|
||||
make.centerY.offset(0);
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (NSMutableArray<SCPlayItemView *> *)itemViews {
|
||||
if (!_itemViews) {
|
||||
_itemViews = NSMutableArray.array;
|
||||
}
|
||||
return _itemViews;
|
||||
}
|
||||
|
||||
@end
|
||||
20
Example/SellyCloudSDK/Play/SCPlayItemModel.h
Normal file
20
Example/SellyCloudSDK/Play/SCPlayItemModel.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// SCLiveItemModel.h
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SCPlayItemModel : NSObject
|
||||
@property (nonatomic, assign)NSInteger type;
|
||||
@property (nonatomic, strong)NSString *title;
|
||||
|
||||
@property (nonatomic, strong)void(^clickCallback)(void);
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
13
Example/SellyCloudSDK/Play/SCPlayItemModel.m
Normal file
13
Example/SellyCloudSDK/Play/SCPlayItemModel.m
Normal file
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// SCLiveItemModel.m
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SCPlayItemModel.h"
|
||||
|
||||
@implementation SCPlayItemModel
|
||||
|
||||
@end
|
||||
18
Example/SellyCloudSDK/Play/SCPlayItemView.h
Normal file
18
Example/SellyCloudSDK/Play/SCPlayItemView.h
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// SCLiveItemView.h
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "SCPlayItemModel.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SCPlayItemView : UIView
|
||||
@property (nonatomic, strong)SCPlayItemModel *model;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
54
Example/SellyCloudSDK/Play/SCPlayItemView.m
Normal file
54
Example/SellyCloudSDK/Play/SCPlayItemView.m
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// SCLiveItemView.m
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 21/7/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SCPlayItemView.h"
|
||||
|
||||
@interface SCPlayItemView ()
|
||||
@property (nonatomic, strong)UIButton *btn;
|
||||
@end
|
||||
|
||||
@implementation SCPlayItemView
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self setupView];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)btnClick {
|
||||
if (self.model.clickCallback) {
|
||||
self.model.clickCallback();
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupView {
|
||||
[self addSubview:self.btn];
|
||||
[self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.size.mas_equalTo(CGSizeMake(80, 30));
|
||||
make.center.equalTo(self);
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setModel:(SCPlayItemModel *)model {
|
||||
_model = model;
|
||||
[self.btn setTitle:model.title forState:UIControlStateNormal];
|
||||
}
|
||||
|
||||
- (UIButton *)btn {
|
||||
if (!_btn) {
|
||||
_btn = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[_btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
|
||||
_btn.titleLabel.font = [UIFont systemFontOfSize:16];
|
||||
}
|
||||
return _btn;
|
||||
}
|
||||
|
||||
@end
|
||||
19
Example/SellyCloudSDK/Play/SCVideoPlayerViewController.h
Normal file
19
Example/SellyCloudSDK/Play/SCVideoPlayerViewController.h
Normal file
@@ -0,0 +1,19 @@
|
||||
//
|
||||
// SCVODPlayerViewController.h
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 16/9/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <SellyCloudSDK/SellyCloudManager.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SCVideoPlayerViewController : UIViewController
|
||||
@property (nonatomic, strong)NSString *url;
|
||||
@property (nonatomic, strong)SellyPlayerStreamInfo *streamInfo;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
218
Example/SellyCloudSDK/Play/SCVideoPlayerViewController.m
Normal file
218
Example/SellyCloudSDK/Play/SCVideoPlayerViewController.m
Normal file
@@ -0,0 +1,218 @@
|
||||
//
|
||||
// SCVODPlayerViewController.m
|
||||
// SellyCloudSDK_Example
|
||||
//
|
||||
// Created by Caleb on 16/9/25.
|
||||
// Copyright © 2025 Caleb. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SCVideoPlayerViewController.h"
|
||||
#import <SellyCloudSDK/SellyCloudManager.h>
|
||||
#import <Masonry/Masonry.h>
|
||||
#import "SCPlayItemContainerView.h"
|
||||
#import <Photos/Photos.h>
|
||||
#import <MediaPlayer/MediaPlayer.h>
|
||||
|
||||
@interface SCVideoPlayerViewController ()<SellyPlayerManagerDelegate>
|
||||
//模拟同时播放多个player
|
||||
//@property (nonatomic, strong)NSMutableArray<SellyCloudRtmpPlayer *> *players;
|
||||
@property (nonatomic, strong)SellyVideoPlayer *player;
|
||||
@property (nonatomic, strong)UIView *v1;
|
||||
@property (nonatomic, strong)UIView *v2;
|
||||
@property (nonatomic, strong)SCPlayItemContainerView *containerView;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SCVideoPlayerViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
self.view.backgroundColor = UIColor.whiteColor;
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
[self.view addSubview:self.v1];
|
||||
[self.v1 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.top.right.equalTo(self.view);
|
||||
make.height.offset(400);
|
||||
}];
|
||||
|
||||
[self.view addSubview:self.v2];
|
||||
[self.v2 mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.bottom.right.equalTo(self.view);
|
||||
make.top.equalTo(self.v1.mas_bottom);
|
||||
}];
|
||||
|
||||
[self.view addSubview:self.containerView];
|
||||
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.right.offset(0);
|
||||
make.bottom.offset(-48);
|
||||
make.height.offset(100);
|
||||
}];
|
||||
[self startPlay];
|
||||
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
||||
}
|
||||
|
||||
- (void)viewDidLayoutSubviews {
|
||||
[self.view bringSubviewToFront:self.containerView];
|
||||
}
|
||||
|
||||
- (void)startPlay {
|
||||
{
|
||||
SellyVideoPlayer *player;
|
||||
if (self.streamInfo) {
|
||||
player = [[SellyVideoPlayer alloc] initWithStreamInfo:self.streamInfo];
|
||||
}
|
||||
else {
|
||||
player = [[SellyVideoPlayer alloc] initWithUrl:[NSURL URLWithString:self.url]];
|
||||
}
|
||||
player.view.frame = self.view.bounds;
|
||||
player.delegate = self;
|
||||
player.scaleMode = SellyPlayerScalingModeAspectFit;
|
||||
player.shouldAutoplay = true;
|
||||
[player prepareToPlay];
|
||||
[self.view addSubview:player.view];
|
||||
self.player = player;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
NSMutableArray *items = NSMutableArray.new;
|
||||
{
|
||||
SCPlayItemModel *model = SCPlayItemModel.new;
|
||||
model.type = 1;
|
||||
model.title = @"播放/暂停";
|
||||
model.clickCallback = ^{
|
||||
if (weakSelf.player.isPlaying) {
|
||||
[weakSelf pause];
|
||||
}
|
||||
else {
|
||||
[weakSelf start];
|
||||
}
|
||||
};
|
||||
[items addObject:model];
|
||||
}
|
||||
{
|
||||
SCPlayItemModel *model = SCPlayItemModel.new;
|
||||
model.type = 2;
|
||||
model.title = @"静音";
|
||||
model.clickCallback = ^{
|
||||
weakSelf.player.playbackVolume = 1-weakSelf.player.playbackVolume;
|
||||
};
|
||||
[items addObject:model];
|
||||
}
|
||||
{
|
||||
SCPlayItemModel *model = SCPlayItemModel.new;
|
||||
model.type = 3;
|
||||
model.title = @"截图";
|
||||
model.clickCallback = ^{
|
||||
[weakSelf saveCurrentFrameToPhotoAlbum:weakSelf.player.getCurrentImage];
|
||||
};
|
||||
[items addObject:model];
|
||||
}
|
||||
{
|
||||
SCPlayItemModel *model = SCPlayItemModel.new;
|
||||
model.type = 4;
|
||||
model.title = @"+10s";
|
||||
model.clickCallback = ^{
|
||||
weakSelf.player.currentPlaybackTime = weakSelf.player.currentPlaybackTime+10;
|
||||
};
|
||||
[items addObject:model];
|
||||
}
|
||||
self.containerView.models = items;
|
||||
}
|
||||
|
||||
- (void)player:(SellyVideoPlayer *)player prepareToPlayChanged:(BOOL)prepare {
|
||||
|
||||
}
|
||||
|
||||
- (void)player:(SellyVideoPlayer *)player playbackDidFinished:(NSDictionary *)resultInfo {
|
||||
|
||||
}
|
||||
|
||||
- (void)player:(SellyVideoPlayer *)player playbackStateChanged:(SellyPlayerState)state {
|
||||
|
||||
}
|
||||
|
||||
- (void)player:(SellyVideoPlayer *)player onError:(NSError *)error {
|
||||
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
[self.player play];
|
||||
}
|
||||
|
||||
- (void)pause {
|
||||
[self.player pause];
|
||||
}
|
||||
|
||||
// 假设 self.session 是你的 LFLiveSession 实例
|
||||
- (void)saveCurrentFrameToPhotoAlbum:(UIImage *)image {
|
||||
if (!image) {
|
||||
NSLog(@"当前没有图像可保存");
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
|
||||
if (status == PHAuthorizationStatusDenied || status == PHAuthorizationStatusRestricted) {
|
||||
NSLog(@"无权限访问相册,请到设置中开启权限");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status == PHAuthorizationStatusNotDetermined) {
|
||||
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus newStatus) {
|
||||
if (newStatus == PHAuthorizationStatusAuthorized) {
|
||||
[self saveImage:image];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
[self saveImage:image];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)saveImage:(UIImage *)image {
|
||||
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL);
|
||||
}
|
||||
|
||||
// 保存完成回调
|
||||
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
|
||||
if (error) {
|
||||
NSLog(@"保存失败:%@", error.localizedDescription);
|
||||
} else {
|
||||
NSLog(@"已保存当前视频帧至相册");
|
||||
}
|
||||
}
|
||||
|
||||
- (UIView *)v1 {
|
||||
if (!_v1) {
|
||||
_v1 = [[UIView alloc] init];
|
||||
// _v1.backgroundColor = [UIColor systemPinkColor];
|
||||
}
|
||||
return _v1;
|
||||
}
|
||||
|
||||
- (UIView *)v2 {
|
||||
if (!_v2) {
|
||||
_v2 = [[UIView alloc] init];
|
||||
// _v2.backgroundColor = [UIColor systemPinkColor];
|
||||
}
|
||||
return _v2;
|
||||
}
|
||||
|
||||
- (SCPlayItemContainerView *)containerView {
|
||||
if (!_containerView) {
|
||||
_containerView = [[SCPlayItemContainerView alloc] init];
|
||||
}
|
||||
return _containerView;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[UIApplication sharedApplication].idleTimerDisabled = NO;
|
||||
NSLog(@"###%@ dealloc",NSStringFromClass(self.class));
|
||||
}
|
||||
|
||||
- (void)viewDidDisappear:(BOOL)animated {
|
||||
[super viewDidDisappear:animated];
|
||||
[self.player stop];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user