Commit 8d4e0972 authored by Han Ruisong's avatar Han Ruisong
Browse files

升级到 4.1.0

1.新增视频投屏功能。
2.优化视频问答流程。
3.将resource.bundle修改为DWResource.bundle防止引入冲突。
parent b5541ffd
No preview for this file type
This diff is collapsed.
......@@ -92,9 +92,7 @@
-(void)reloadLoaclData
{
//请自行替换数据
NSArray * videos = @[];
NSArray * videos = @[];
for (int i = 0; i < videos.count; i++) {
DWVodModel * vodModel = [[DWVodModel alloc]init];
......
//
// DWScreeningListViewController.h
// Demo
//
// Created by zwl on 2019/7/9.
// Copyright © 2019 com.bokecc.www. All rights reserved.
//
#import "DWBaseViewController.h"
@class DWUPnPDevice;
NS_ASSUME_NONNULL_BEGIN
@protocol DWScreeningListViewControllerDelegate <NSObject>
-(void)screeningReturnButtonAction;
-(void)screeningListDidSelectAction:(DWUPnPDevice *)device AndPlayUrl:(NSString *)playUrl;
@end
@interface DWScreeningListViewController : DWBaseViewController
@property(nonatomic,weak) id <DWScreeningListViewControllerDelegate> delegate;
@property(nonatomic,copy)NSString * playUrl;
@end
NS_ASSUME_NONNULL_END
//
// DWScreeningListViewController.m
// Demo
//
// Created by zwl on 2019/7/9.
// Copyright © 2019 com.bokecc.www. All rights reserved.
//
#import "DWScreeningListViewController.h"
#import "DWScreeningTableViewCell.h"
#import "DWUPnPSearch.h"
#import "DWUPnPDevice.h"
#import "DWUPnPRenderer.h"
#import <AVKit/AVKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface DWScreeningListViewController () <UITableViewDelegate,UITableViewDataSource,DWUPnPSearchDelegate>
@property(nonatomic,strong)DWUPnPSearch * upnpSearch;
@property(nonatomic,strong)DWUPnPRenderer * renderer;
@property(nonatomic,strong)UIView * headerView;
@property(nonatomic,strong)UILabel * statusLabel;
@property(nonatomic,strong)UIView * searchingBgView;//搜索中
@property(nonatomic,strong)UIView * noDevicesBgView;//未找到设备
@property(nonatomic,strong)UIView * screeningFailedBgView;//投屏失败
@property(nonatomic,strong)MPVolumeView * volumeView;//ariPlay
@property(nonatomic,strong)NSArray * listArray;
@property(nonatomic,strong)UITableView * tableView;
@end
@implementation DWScreeningListViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self initUI];
self.upnpSearch = [[DWUPnPSearch alloc]init];
self.upnpSearch.delegate = self;
[self.upnpSearch start];
}
-(void)dealloc
{
[self.upnpSearch destroy];
self.upnpSearch = nil;
NSLog(@"DWScreeningListViewController dealloc");
}
#pragma mark - action
-(void)returnButtonAction
{
if ([self.delegate respondsToSelector:@selector(screeningReturnButtonAction)]) {
[self.delegate screeningReturnButtonAction];
}
[self.navigationController popViewControllerAnimated:YES];
}
-(void)refreshButtonAction
{
self.statusLabel.text = [NSString stringWithFormat:@"当前WiFi:%@",[DWTools getWifiName]];
self.headerView.frame = CGRectMake(0, 0, ScreenWidth, 44 + 10 + 44);
self.tableView.tableHeaderView = self.headerView;
self.noDevicesBgView.hidden = YES;
self.screeningFailedBgView.hidden = YES;
self.searchingBgView.hidden = NO;
[self.upnpSearch refresh];
}
#pragma mark - delegate
//DWUPnPSearchDelegate
//搜索结果
-(void)upnpSearchChangeWithResults:(NSArray <DWUPnPDevice *>*)devices
{
NSLog(@"search result %@",devices);
self.listArray = devices;
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
//搜索失败
-(void)upnpSearchErrorWithError:(NSError *)error
{
self.headerView.frame = CGRectMake(0, 0, ScreenWidth, 44 + 10 + 145);
self.tableView.tableHeaderView = self.headerView;
self.noDevicesBgView.hidden = YES;
self.screeningFailedBgView.hidden = NO;
self.searchingBgView.hidden = YES;
[error.localizedDescription showAlert];
}
//tableviewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.listArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 44;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
DWScreeningTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[DWScreeningTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
}
cell.device = [self.listArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (!self.playUrl) {
[@"投屏连接不存在" showAlert];
return;
}
if ([self.playUrl containsString:@".pcm"] || [[NSURL URLWithString:self.playUrl] isFileURL]) {
[@"请使用Airplay投放" showAlert];
return;
}
if ([self.delegate respondsToSelector:@selector(screeningListDidSelectAction:AndPlayUrl:)]) {
DWUPnPDevice * device = [self.listArray objectAtIndex:indexPath.row];
[self.delegate screeningListDidSelectAction:device AndPlayUrl:[self.playUrl copy]];
}
[self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - init
-(void)initUI
{
self.title = @"选择投屏设备";
self.view.backgroundColor = [UIColor colorWithRed:243/255.0 green:244/255.0 blue:245/255.0 alpha:1.0];
//导航功能按钮
UIButton * refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
[refreshButton setImage:[UIImage imageNamed:@"icon_screen_refresh.png"] forState:UIControlStateNormal];
refreshButton.frame = CGRectMake(0, 0, 40, 40);
[refreshButton addTarget:self action:@selector(refreshButtonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem * rightItem = [[UIBarButtonItem alloc]initWithCustomView:refreshButton];
self.navigationItem.rightBarButtonItem = rightItem;
self.tableView = [[UITableView alloc]init];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
self.tableView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.tableView];
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@0);
make.top.equalTo(@0);
make.width.equalTo(@(ScreenWidth));
make.bottom.equalTo(@(-80));
}];
self.headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 88 + 10)];
self.headerView.backgroundColor = self.view.backgroundColor;
self.tableView.tableHeaderView = self.headerView;
self.statusLabel = [[UILabel alloc]init];
self.statusLabel.font = TitleFont(14);
self.statusLabel.textColor = TitleColor_102;
self.statusLabel.textAlignment = NSTextAlignmentLeft;
[self.headerView addSubview:self.statusLabel];
[_statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@10);
make.right.equalTo(@(-10));
make.top.equalTo(@0);
make.height.equalTo(@44);
}];
//iOS12下,请设置Target -> Capabilities -> Access WiFi Information -> ON,否则会查找不到wifi名字
self.statusLabel.text = [NSString stringWithFormat:@"当前WiFi:%@",[DWTools getWifiName]];
//未找到设备
[self.headerView addSubview:self.noDevicesBgView];
self.noDevicesBgView.hidden = YES;
[_noDevicesBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.equalTo(@0);
make.top.equalTo(self.statusLabel.mas_bottom);
make.height.equalTo(@195);
}];
//搜索失败
[self.headerView addSubview:self.screeningFailedBgView];
self.screeningFailedBgView.hidden = YES;
[_screeningFailedBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.equalTo(@0);
make.top.equalTo(self.statusLabel.mas_bottom);
make.height.equalTo(@145);
}];
//搜索中
[self.headerView addSubview:self.searchingBgView];
[_searchingBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.and.right.equalTo(@0);
make.top.equalTo(self.statusLabel.mas_bottom);
make.height.equalTo(@44);
}];
self.volumeView = [[MPVolumeView alloc]init];
self.volumeView.showsVolumeSlider = NO;
[self.volumeView setRouteButtonImage:[UIImage imageNamed:@"icon_screen_airplay_bg.png"] forState:UIControlStateNormal];
[self.view addSubview:self.volumeView];
[_volumeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.width.equalTo(@145);
make.height.equalTo(@40);
make.top.equalTo(self.tableView.mas_bottom).offset(15);
}];
}
-(UIView *)searchingBgView
{
if (!_searchingBgView) {
_searchingBgView = [[UIView alloc]init];
_searchingBgView.backgroundColor = [UIColor whiteColor];
NSString * str = @"正在搜索可投屏设备...";
UIActivityIndicatorView * aiView = [[UIActivityIndicatorView alloc]init];
aiView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[aiView startAnimating];
[_searchingBgView addSubview:aiView];
UILabel * label = [[UILabel alloc]init];
label.text = str;
label.textColor = TitleColor_51;
label.font = TitleFont(15);
[_searchingBgView addSubview:label];
CGFloat x = (ScreenWidth - (15 + 5 + 150)) / 2.0;
[aiView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(@(x));
make.centerY.equalTo(_searchingBgView);
make.width.equalTo(@(15));
make.height.equalTo(@(15));
}];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(aiView.mas_right).offset(5);
make.centerY.equalTo(aiView);
make.height.equalTo(@15);
make.width.equalTo(@(150));
}];
}
return _searchingBgView;
}
-(UIView *)noDevicesBgView
{
if (!_noDevicesBgView) {
_noDevicesBgView = [[UIView alloc]init];
_noDevicesBgView.backgroundColor = [UIColor whiteColor];
UILabel * tsLabel = [[UILabel alloc]init];
tsLabel.text = @"当前网络下暂未找到可投屏设备";
tsLabel.font = TitleFont(15);
tsLabel.textColor = TitleColor_51;
tsLabel.textAlignment = NSTextAlignmentCenter;
[_noDevicesBgView addSubview:tsLabel];
[tsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@15);
make.height.equalTo(@15);
make.left.and.right.equalTo(@0);
}];
UILabel * contentLabel = [[UILabel alloc]init];
contentLabel.text = @" 1、请确认设备是否是可投屏设备,如智能电视、智能盒子、电视果及其他投屏设备。如果无法确认,可咨询设备厂商。\n\n 2、请确保手机和设备连接在同一个Wi-Fi下。\n\n 3、重新启动APP,再次尝试投屏。";
contentLabel.font = TitleFont(13);
contentLabel.textColor = TitleColor_102;
contentLabel.textAlignment = NSTextAlignmentLeft;
contentLabel.numberOfLines = 0;
[_noDevicesBgView addSubview:contentLabel];
[contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(tsLabel.mas_bottom).offset(20);
make.left.and.right.equalTo(@0);
make.height.equalTo(@120);
}];
}
return _noDevicesBgView;
}
-(UIView *)screeningFailedBgView
{
if (!_screeningFailedBgView) {
_screeningFailedBgView = [[UIView alloc]init];
_screeningFailedBgView.backgroundColor = [UIColor whiteColor];
UILabel * tsLabel = [[UILabel alloc]init];
tsLabel.text = @"投屏连接失败";
tsLabel.font = TitleFont(15);
tsLabel.textColor = TitleColor_51;
tsLabel.textAlignment = NSTextAlignmentCenter;
[_screeningFailedBgView addSubview:tsLabel];
[tsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@15);
make.height.equalTo(@15);
make.left.and.right.equalTo(@0);
}];
UILabel * contentLabel = [[UILabel alloc]init];
contentLabel.text = @" 1、请确保手机与投屏设备连接在同一个WiFi下。\n\n 2、请重新投屏或重启APP再次尝试。";
contentLabel.font = TitleFont(13);
contentLabel.textColor = TitleColor_102;
contentLabel.textAlignment = NSTextAlignmentLeft;
contentLabel.numberOfLines = 0;
[_screeningFailedBgView addSubview:contentLabel];
[contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(tsLabel.mas_bottom).offset(20);
make.left.and.right.equalTo(@0);
make.height.equalTo(@70);
}];
}
return _screeningFailedBgView;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
......@@ -12,13 +12,15 @@
#import "DWVodPlayerView.h"
#import "DWAdShouView.h"
#import "DWNetworkMonitorViewController.h"
#import "DWScreeningListViewController.h"
#import "DWScreeningBgView.h"
typedef enum : NSUInteger {
DWVodPlayTableViewCellStyleDefault,
DWVodPlayTableViewCellStyleChoose,
} DWVodPlayTableViewCellStyle;
@interface DWVodPlayViewController ()<UITableViewDelegate,UITableViewDataSource,DWVodPlayBottomViewDelegate,DWVodPlayerViewDelegate,DWAdShouViewDelegate>
@interface DWVodPlayViewController ()<UITableViewDelegate,UITableViewDataSource,DWVodPlayBottomViewDelegate,DWVodPlayerViewDelegate,DWAdShouViewDelegate,DWScreeningListViewControllerDelegate,DWScreeningBgViewDelegate>
@property(nonatomic,assign)CGSize playerViewSize;
@property(nonatomic,strong)DWVodPlayerView * playerView;
......@@ -29,6 +31,8 @@ typedef enum : NSUInteger {
@property(nonatomic,strong)DWAdShouView * adShowView;//广告
@property(nonatomic,strong)DWScreeningBgView * screenBgView;//投屏控制器
@end
@implementation DWVodPlayViewController
......@@ -140,6 +144,14 @@ typedef enum : NSUInteger {
make.left.and.top.equalTo(@0);
make.right.and.bottom.equalTo(@0);
}];
if (self.screenBgView) {
[_screenBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.left.and.top.equalTo(@0);
make.right.and.bottom.equalTo(@0);
}];
}
}else{
[_playerView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.equalTo(@0);
......@@ -152,10 +164,22 @@ typedef enum : NSUInteger {
make.width.equalTo(@(self.playerViewSize.width));
make.height.equalTo(@(self.playerViewSize.height));
}];
if (self.screenBgView) {
[_screenBgView mas_remakeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.equalTo(@0);
make.width.equalTo(@(self.playerViewSize.width));
make.height.equalTo(@(self.playerViewSize.height));
}];
}
}
[self.adShowView screenRotate:isFull];
[self.playerView reLayoutWithScreenState:isFull];
if (self.screenBgView) {
[self.screenBgView screenRotate:isFull];
}
}
#pragma mark - notification
......@@ -249,6 +273,17 @@ typedef enum : NSUInteger {
[self.listTableView reloadData];
}
//投屏事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView ScreeningJumpAction:(NSString *)playUrl
{
DWScreeningListViewController * screeningListVC = [[DWScreeningListViewController alloc]init];
screeningListVC.playUrl = playUrl;
screeningListVC.delegate = self;
[self.navigationController pushViewController:screeningListVC animated:YES];
self.playerView.isScreening = YES;
}
//网络检测事件
-(void)vodPlayerView:(DWVodPlayerView *)playerView DidNetworkMonitor:(NSString *)vid AndPlayUrl:(NSString *)playUrl
{
......@@ -271,6 +306,36 @@ typedef enum : NSUInteger {
});
}
#pragma mark - 投屏相关
-(void)screeningReturnButtonAction
{
self.playerView.isScreening = NO;
}
-(void)screeningListDidSelectAction:(DWUPnPDevice *)device AndPlayUrl:(NSString *)playUrl
{
self.screenBgView = [[DWScreeningBgView alloc]initWithDevice:device AndPlayUrl:playUrl];
self.screenBgView.delegate = self;
self.screenBgView.title = self.playerView.videoTitle;
self.screenBgView.seekTime = self.playerView.currentPlayDuration;
[self.view addSubview:self.screenBgView];
[_screenBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.equalTo(@0);
make.width.equalTo(@(self.playerViewSize.width));
make.height.equalTo(@(self.playerViewSize.height));
}];
}
-(void)screeningBgViewCloseAction
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.screenBgView removeFromSuperview];
self.screenBgView = nil;
});
}
#pragma mark - tabelViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
......@@ -300,6 +365,12 @@ typedef enum : NSUInteger {
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.playerView.isScreening) {
//正在投屏
[@"正在投屏中,请退出投屏再切换视频" showAlert];
return;
}
DWVodModel * vodModel = [self.vidoeList objectAtIndex:indexPath.row];
if ([vodModel.videoId isEqualToString:self.vodModel.videoId]) {
......
......@@ -25,6 +25,8 @@ typedef NS_ENUM(NSInteger, DWVodSettingStyle) {
//DWVodSettingStyleTotal 回调
//下载回调
-(void)playerSettingViewDownloadAction;
//投屏回调
-(void)playerSettingViewScreeningAction;
//音视频回调
-(void)playerSettingViewMediaTypeAction;
//网络检测回调
......
......@@ -84,7 +84,7 @@ static NSInteger setSectionListTableHeight = 60;
return;
}
DWSettingFuncButton * mediaTypeButton = (DWSettingFuncButton *)[self.bgScrollView viewWithTag:101];
DWSettingFuncButton * mediaTypeButton = (DWSettingFuncButton *)[self.bgScrollView viewWithTag:102];
mediaTypeButton.selected = isVideo;
self.sizeArray = sizeList;
......@@ -183,13 +183,20 @@ static NSInteger setSectionListTableHeight = 60;
}
}
if (button.tag == 101) {
//投屏
if ([_delegate respondsToSelector:@selector(playerSettingViewScreeningAction)]) {
[_delegate playerSettingViewScreeningAction];
}
}
if (button.tag == 102) {
//音视频切换
button.selected = !button.selected;
if ([_delegate respondsToSelector:@selector(playerSettingViewMediaTypeAction)]) {
[_delegate playerSettingViewMediaTypeAction];
}
}
if (button.tag == 102) {
if (button.tag == 103) {
//网络检测
if ([_delegate respondsToSelector:@selector(playerSettingViewNetworkMonitorAction)]) {
[_delegate playerSettingViewNetworkMonitorAction];
......@@ -350,16 +357,16 @@ static NSInteger setSectionListTableHeight = 60;
self.bgScrollView.frame = CGRectMake(0, 0, self.bgView.frame.size.width, self.bgView.frame.size.height);
[self.bgView addSubview:self.bgScrollView];
NSArray * titles = @[@"下载",@"视频播放",@"网络检测"];
NSArray * images = @[@"icon_setting_dwonload.png",@"icon_setting_video.png",@"icon_setting_network.png"];
CGFloat buttonWidth = 58.0;
CGFloat space = (self.bgView.frame.size.width - buttonWidth * 3 - 10 * 2) / 2.0;
NSArray * titles = @[@"下载",@"投屏",@"视频播放",@"网络检测"];