Files
ifish/Ifish/controllers/IfishYooseeFile/IfishYooseeControlller/IfishP2PPlayBack/P2PPlayingbackVC.m
T

888 lines
32 KiB
Objective-C

//
// P2PPlayingbackVC.m
// P2PPlayingbackVC
//
// Created by apple on 16/7/19.
// Copyright © 2016年 yuanHongQiang. All rights reserved.
//
#import "P2PPlayingbackVC.h"
#import "FounderButton.h"
#import "UIViewExt.h"
#import "YSlider.h"
#import "AppDelegate.h"
#import "PAIOUnit.h"
#import "OpenGLView.h"
#import "FListManager.h"
@interface P2PPlayingbackVC ()
@property (nonatomic) CGPoint swipeLastPos;
@property (nonatomic,strong) OpenGLView *remoteView;
@end
@implementation P2PPlayingbackVC{
BOOL _hadRotating;
BOOL _hadLayout;
BOOL _hadCreateUI;
BOOL _hadAddUI;
UIView* _viewNaviBar;
UIImageView* _imageViewNaviBarColor;
UIView* _viewBottomTools;
UIView* _openGLView;
UIView* _viewSpeed;
FounderButton* _buttonPre;
FounderButton* _buttonNext;
FounderButton* _buttonSpeed;
FounderButton* _buttonPause;
FounderButton* _buttonSilence;
FounderButton* _buttonBack;
FounderButton* _buttonViewSpeed;
UITapGestureRecognizer* _gesOnceTap;
UILabel* _labelPlayTheTime;
UILabel* _labelPlayAllTime;
UILabel* _labelPlaySpeedTime;
YSlider* _sliderPlayProgress;
BOOL _isPause;
BOOL _isSilence;
BOOL _isFasting;
//
BOOL _needUpdatePlayTimeShow;
//OpenGLView *_remoteView;
uint64_t _theTimePlay;
uint64_t _theTimeAll;
NSString* _thetimePlayStr;
NSString* _thetimeAllStr;
BOOL _isFishEyeDevice;
CGSize _theSizeOfScreen;
}
-(void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
-(void)regStatusBarNotification{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(notHadRotating:)
name:UIApplicationDidChangeStatusBarOrientationNotification
object:nil];
}
-(void)notHadRotating:(NSNotification*)notification{
_hadRotating=YES;
_hadLayout=NO;
}
-(instancetype)init{
self=[super init];
if (self) {
[self initializeVariable];
[self regStatusBarNotification];
}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
[AppDelegate sharedDefault].canFullScreen = YES;
self.view.backgroundColor=[UIColor whiteColor];
[self createUI];
[self addUI];
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[self stSilence:NO];
[[PAIOUnit sharedUnit] setSilentAudio:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
- (void)applicationDidEnterBackground {
NSLog(@"========================Enter Background");
_isReject = YES;
}
- (void)applicationDidBecomeActive {
NSLog(@"========================Become Active");
_isReject = NO;
[self startRenderView];
}
-(void)initializeVariable{
_hadRotating=NO;
_hadLayout=NO;
_hadCreateUI=NO;
_hadAddUI=NO;
_isPause=NO;
_isSilence=NO;
_isFasting=NO;
_needUpdatePlayTimeShow=YES;
}
-(void)createUI{
_hadCreateUI=YES;
_viewNaviBar=[[UIView alloc] init];
_viewNaviBar.backgroundColor=[UIColor clearColor];
_imageViewNaviBarColor=[[UIImageView alloc] init];
_imageViewNaviBarColor.backgroundColor=[UIColor clearColor];
_imageViewNaviBarColor.contentMode=UIViewContentModeScaleToFill;
_imageViewNaviBarColor.image=[UIImage imageNamed:@"FullPlay_Gradient_black_alpha_0.png"];
_viewBottomTools=[[UIView alloc] init];
_viewBottomTools.backgroundColor=[UIColor colorWithRed:48/255.0 green:48/255.0 blue:48/255.0 alpha:0.8];
_openGLView=[[UIView alloc] init];
_openGLView.backgroundColor=[UIColor blackColor];
// _openGLView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"FullScreenTemp.png"]];
_gesOnceTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showToolsViewChange)];
_gesOnceTap.numberOfTapsRequired=1;
[_openGLView addGestureRecognizer:_gesOnceTap];
_buttonPre=[[FounderButton alloc] init];
_buttonPre.buttonImageViewSize=CGSizeMake(17, 17);
_buttonPre.backgroundColor=[UIColor clearColor];
[_buttonPre addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[_buttonPre setImage:[UIImage imageNamed:@"FullPlay_Previous.png"] forState:UIControlStateNormal];
[_buttonPre setImage:[UIImage imageNamed:@"FullPlay_Previous_down.png"] forState:UIControlStateHighlighted];
_buttonNext=[[FounderButton alloc] init];
_buttonNext.buttonImageViewSize=CGSizeMake(17, 17);
_buttonNext.backgroundColor=[UIColor clearColor];
[_buttonNext addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[_buttonNext setImage:[UIImage imageNamed:@"FullPlay_Next.png"] forState:UIControlStateNormal];
[_buttonNext setImage:[UIImage imageNamed:@"FullPlay_Next_down.png"] forState:UIControlStateHighlighted];
_buttonSpeed=[[FounderButton alloc] init];
_buttonSpeed.buttonImageViewSize=CGSizeMake(17, 17);
_buttonSpeed.backgroundColor=[UIColor clearColor];
[_buttonSpeed addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[_buttonSpeed setImage:[UIImage imageNamed:@"FullPlay_Speed.png"] forState:UIControlStateNormal];
[_buttonSpeed setImage:[UIImage imageNamed:@"FullPlay_Speed_down.png"] forState:UIControlStateHighlighted];
_buttonPause=[[FounderButton alloc] init];
_buttonPause.buttonImageViewSize=CGSizeMake(17, 17);
_buttonPause.backgroundColor=[UIColor clearColor];
[_buttonPause addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[self updatePauseButtonWithPause:_isPause];
_buttonSilence=[[FounderButton alloc] init];
_buttonSilence.buttonImageViewSize=CGSizeMake(17, 17);
_buttonSilence.backgroundColor=[UIColor clearColor];
[_buttonSilence addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[self updateSilenceButtonWithPause:_isSilence];
_buttonBack=[[FounderButton alloc] init];
_buttonBack.buttonImageViewSize=CGSizeMake(17, 17);
_buttonBack.backgroundColor=[UIColor clearColor];
[_buttonBack addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[_buttonBack setImage:[UIImage imageNamed:@"FullPlay_Back.png"] forState:UIControlStateNormal];
[_buttonBack setImage:[UIImage imageNamed:@"FullPlay_Back_down.png"] forState:UIControlStateHighlighted];
_labelPlayTheTime=[[UILabel alloc] init];
_labelPlayTheTime.userInteractionEnabled=NO;
_labelPlayTheTime.backgroundColor=[UIColor clearColor];
_labelPlayTheTime.text=@"00:00:00";
_labelPlayTheTime.textColor=[UIColor whiteColor];
_labelPlayTheTime.font=[UIFont systemFontOfSize:11.0];
_labelPlayTheTime.textAlignment=NSTextAlignmentLeft;
_labelPlayAllTime=[[UILabel alloc] init];
_labelPlayAllTime.userInteractionEnabled=NO;
_labelPlayAllTime.backgroundColor=[UIColor clearColor];
_labelPlayAllTime.text=@"00:00:00";
_labelPlayAllTime.textColor=[UIColor whiteColor];
_labelPlayAllTime.font=[UIFont systemFontOfSize:11.0];
_labelPlayAllTime.textAlignment=NSTextAlignmentRight;
_sliderPlayProgress=[[YSlider alloc] init];
_sliderPlayProgress.backgroundColor=[UIColor clearColor];
[_sliderPlayProgress setMinimumTrackColor:[UIColor colorWithRed:102/255.0 green:185/255.0 blue:255/255.0 alpha:1.0]
forState:UIControlStateNormal];
[_sliderPlayProgress setMinimumTrackColor:[UIColor colorWithRed:102/255.0 green:185/255.0 blue:255/255.0 alpha:1.0]
forState:UIControlStateHighlighted];
[_sliderPlayProgress setMinimumTrackColor:[UIColor colorWithRed:102/255.0 green:185/255.0 blue:255/255.0 alpha:1.0]
forState:UIControlStateSelected];
[_sliderPlayProgress setMaximumTrackColor:[UIColor colorWithRed:118/255.0 green:118/255.0 blue:118/255.0 alpha:1.0]
forState:UIControlStateNormal];
[_sliderPlayProgress setMaximumTrackColor:[UIColor colorWithRed:118/255.0 green:118/255.0 blue:118/255.0 alpha:1.0]
forState:UIControlStateHighlighted];
[_sliderPlayProgress setMaximumTrackColor:[UIColor colorWithRed:118/255.0 green:118/255.0 blue:118/255.0 alpha:1.0]
forState:UIControlStateSelected];
[_sliderPlayProgress setThumbImage:[UIImage imageNamed:@"FullPlay_Slider.png"] forState:UIControlStateNormal];
[_sliderPlayProgress setThumbImage:[UIImage imageNamed:@"FullPlay_Slider_down.png"] forState:UIControlStateHighlighted];
[_sliderPlayProgress setThumbImage:[UIImage imageNamed:@"FullPlay_Slider_down.png"] forState:UIControlStateSelected];
[_sliderPlayProgress setThumbColor:[UIColor clearColor] forState:UIControlStateNormal];
[_sliderPlayProgress setThumbColor:[UIColor clearColor] forState:UIControlStateHighlighted];
[_sliderPlayProgress setThumbColor:[UIColor clearColor] forState:UIControlStateSelected];
_sliderPlayProgress.value=0.0;
_sliderPlayProgress.thumbSize=CGSizeMake(21, 21);
[_sliderPlayProgress addTarget:self action:@selector(dropInsideBegin:) forControlEvents:UIControlEventTouchDown];
[_sliderPlayProgress addTarget:self action:@selector(dropValueChange:) forControlEvents:UIControlEventValueChanged];
[_sliderPlayProgress addTarget:self action:@selector(dropInsideEnd:) forControlEvents:UIControlEventTouchUpInside];
[_sliderPlayProgress addTarget:self action:@selector(dropCancel:) forControlEvents:UIControlEventTouchUpOutside];
[_sliderPlayProgress addTarget:self action:@selector(dropCancel:) forControlEvents:UIControlEventTouchCancel];
//画布
//画布
NSString *contactId = [[P2PClient sharedClient] callId];
// NSInteger deviceSubtype = [[FListManager sharedFList] getDeviceSubtypeWithId:contactId];
_isFishEyeDevice = NO;
//if (isSupportFisheyeDevice(deviceSubtype)) {
// _isFishEyeDevice = YES;
// }
//非鱼眼设备 下面设置无效
int installType = SHAPE_CIRCLE;//360
int fishEyeType = FISHEYE_360;//360
// if (isSupportFisheyeDevice180(deviceSubtype)) {
// installType = SHAPE_180_HALF_SPHERE;//180
// fishEyeType = FISHEYE_180;//180
// }
_remoteView = [[OpenGLView alloc] initWithIsSupportFisheyeDevice:_isFishEyeDevice installType:installType deviceID:[contactId intValue] fishEyeType:fishEyeType];
_remoteView.userInteractionEnabled=YES;
[_remoteView setIsFullScreen:YES];
if (_isFishEyeDevice) {
//缩放手势(鱼眼设备)
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];
[pinchGestureRecognizer addTarget:self action:@selector(onPinchToZoom:)];
[_remoteView addGestureRecognizer:pinchGestureRecognizer];
//拖动手势(鱼眼设备才有,普通设备时则禁止)
UIPanGestureRecognizer *panRec = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panEvent:)];
[_remoteView addGestureRecognizer:panRec];
}
_viewSpeed = [[UIView alloc] init];
_viewSpeed.hidden = YES;
_viewSpeed.backgroundColor=[UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.5];
_buttonViewSpeed = [[FounderButton alloc] init];
_buttonViewSpeed.buttonImageViewSize=CGSizeMake(17, 17);
_buttonViewSpeed.backgroundColor=[UIColor clearColor];
[_buttonViewSpeed addTarget:self action:@selector(buttonBeClick:) forControlEvents:UIControlEventTouchUpInside];
[_buttonViewSpeed setImage:[UIImage imageNamed:@"FullPlay_Speed.png"] forState:UIControlStateNormal];
[_buttonViewSpeed setImage:[UIImage imageNamed:@"FullPlay_Speed_down.png"] forState:UIControlStateHighlighted];
_labelPlaySpeedTime=[[UILabel alloc] init];
_labelPlaySpeedTime.userInteractionEnabled=NO;
_labelPlaySpeedTime.backgroundColor=[UIColor clearColor];
_labelPlaySpeedTime.text=@"00:00:00";
_labelPlaySpeedTime.textColor=[UIColor colorWithRed:102.0/255.0 green:185.0/255.0 blue:255.0/255.0 alpha:1.0];
_labelPlaySpeedTime.font=[UIFont systemFontOfSize:10.0];
_labelPlaySpeedTime.textAlignment=NSTextAlignmentLeft;
}
-(void)addUI{
_hadAddUI=YES;
UIView* theView=self.view;
[_openGLView addSubview:_remoteView];
[theView addSubview:_openGLView];
[_viewBottomTools addSubview:_sliderPlayProgress];
[_viewBottomTools addSubview:_buttonPre];
[_viewBottomTools addSubview:_buttonNext];
[_viewBottomTools addSubview:_buttonPause];
[_viewBottomTools addSubview:_buttonSilence];
[_viewBottomTools addSubview:_labelPlayTheTime];
[_viewBottomTools addSubview:_labelPlayAllTime];
[_viewBottomTools addSubview:_buttonSpeed];
//[theView addSubview:_viewBottomTools];
[_viewNaviBar addSubview:_imageViewNaviBarColor];
[_viewNaviBar addSubview:_buttonBack];
[theView addSubview:_viewNaviBar];
[_viewSpeed addSubview:_buttonViewSpeed];
[_viewSpeed addSubview:_labelPlaySpeedTime];
[theView addSubview:_viewSpeed];
}
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
if (!_hadLayout){
_hadLayout=YES;
}
[self layoutAuto];
if (_hadRotating){
_hadRotating=NO;
}
}
-(CGSize)gtScreenSize{
CGSize screenSize = [UIScreen mainScreen].bounds.size;
if (([[UIDevice currentDevice].systemVersion floatValue] < 8.0) &&
UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
return CGSizeMake(screenSize.height, screenSize.width);
}
return screenSize;
}
-(void)layoutAuto{
_theSizeOfScreen=[self gtScreenSize];
CGFloat TempW=_theSizeOfScreen.width;
CGFloat TempH=45;
CGFloat TempX=0;
CGFloat TempY=(_theSizeOfScreen.height-TempH);
CGRect newRect=CGRectMake(TempX, TempY, TempW, TempH);
_viewBottomTools.frame=newRect;
TempW=_theSizeOfScreen.width;
TempH=_theSizeOfScreen.height;
TempX=0;
TempY=0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_openGLView.frame=newRect;
_remoteView.frame=_openGLView.bounds;
if (_isFishEyeDevice) {
// [_remoteView setFullScreenHeight:_remoteView.frame.size.width width:_remoteView.frame.size.width fullScreen:1];//360全景设备
}
TempW=_theSizeOfScreen.width;
TempH=44;
TempX=0;
TempY=0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_viewNaviBar.frame=newRect;
_imageViewNaviBarColor.frame=_viewNaviBar.bounds;
TempW=35;
TempH=_viewNaviBar.height;
TempX=15;
TempY=(_viewNaviBar.height-TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonBack.frame=newRect;
TempW=33;
TempH=_viewBottomTools.height;
TempX=_buttonBack.left;
TempY=(_viewBottomTools.height-TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonPre.frame=newRect;
TempW=_buttonPre.width;
TempH=_buttonPre.height;
TempX=_buttonPre.right;
TempY=_buttonPre.top;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonPause.frame=newRect;
TempW=_buttonPause.width;
TempH=_buttonPause.height;
TempX=_buttonPause.right;
TempY=_buttonPause.top;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonNext.frame=newRect;
TempW=_buttonNext.width;
TempH=_buttonNext.height;
TempX=_buttonNext.right;
TempY=_buttonNext.top;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonSpeed.frame=newRect;
TempW=_buttonPre.width;
TempH=_buttonPre.height;
TempX=(_viewBottomTools.width-TempW)- _buttonPre.left;
TempY=_buttonPre.top;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonSilence.frame=newRect;
TempW=_buttonSilence.left-_buttonSpeed.right+15*2;
TempH=_viewBottomTools.height;
TempX=_buttonSpeed.right-15;
TempY=(_viewBottomTools.height-TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_sliderPlayProgress.frame=newRect;
TempW=(_sliderPlayProgress.width-_sliderPlayProgress.height/2.0*2)/2.0;
TempH=_viewBottomTools.height/2.0;
TempX=_sliderPlayProgress.left+_sliderPlayProgress.height/2.0;
TempY=_viewBottomTools.height-TempH;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_labelPlayTheTime.frame=newRect;
TempW=(_sliderPlayProgress.width-_sliderPlayProgress.height/2.0*2)/2.0;
TempH=_labelPlayTheTime.height;
TempX=(_sliderPlayProgress.width-(TempW+_sliderPlayProgress.height/2.0))+_sliderPlayProgress.left;;
TempY=_labelPlayTheTime.top;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_labelPlayAllTime.frame=newRect;
TempW=170.0/2.0;
TempH=55.0/2.0;
TempX=(_theSizeOfScreen.width - TempW)/2.0;
TempY=(_theSizeOfScreen.height - TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_viewSpeed.frame=newRect;
TempW=_buttonNext.width;
TempH=_buttonNext.height;
TempX=0.0;
TempY=(_viewSpeed.height - TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_buttonViewSpeed.frame=newRect;
TempW=_viewSpeed.width - _buttonViewSpeed.width;
TempH=_viewSpeed.height / 2.0;
TempX=_buttonViewSpeed.right;
TempY=(_viewSpeed.height - TempH)/2.0;
newRect=CGRectMake(TempX, TempY, TempW, TempH);
_labelPlaySpeedTime.frame = newRect;
}
#pragma mark - 将要显示
-(void)viewWillAppear:(BOOL)animated{
[AppDelegate sharedDefault].canFullScreen = YES;
[super viewWillAppear:animated];
[[P2PClient sharedClient] setPlaybackDelegate:self];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receivePlayingCommand:)
name:RECEIVE_PLAYING_CMD
object:nil];
}
#pragma mark - 收到播放控制消息
- (void)receivePlayingCommand:(NSNotification *)notification{
NSDictionary *parameter = [notification userInfo];
int key = [[parameter valueForKey:@"key"] intValue];
dispatch_async(dispatch_get_main_queue(), ^{
if(key==RECEIVE_PLAYING_CMD_PLAYBACK_STOP){
NSLog(@"停止播放");
_isPause=YES;
_viewSpeed.hidden=YES;
}else if(key==RECEIVE_PLAYING_CMD_PLAYBACK_START){
NSLog(@"开始播放");
_isPause=NO;
}else if(key==RECEIVE_PLAYING_CMD_PLAY_FAST_START){
NSLog(@"开始快进");
_isPause=NO;
_viewSpeed.hidden=NO;
}else if(key==RECEIVE_PLAYING_CMD_PLAY_FAST_STOP){
NSLog(@"停止快进");
_isPause=NO;
_viewSpeed.hidden=YES;
}
[self updatePauseButtonWithPause:_isPause];
});
}
#pragma mark - 将要消失
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self closeThePlay];
[[NSNotificationCenter defaultCenter] removeObserver:self name:RECEIVE_PLAYING_CMD object:nil];
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
}
#pragma mark - 视图已经显示
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self startRenderView];
}
#pragma mark - 时间到文本的转换
-(NSString*)stringFromTime:(uint64_t)time{
uint64_t theTime=time;
if (theTime<=0) {
theTime=0;
}
uint64_t hour=theTime/3600;
uint64_t minutes=(theTime - hour*3600 )/60;
uint64_t seconds=(theTime - hour*3600 - minutes*60);
NSString* strTime=[NSString stringWithFormat:@"%02lld:%02lld:%02lld",(uint64_t)hour,(uint64_t)minutes,(uint64_t)seconds];
return strTime;
}
#pragma mark - 渲染视频
- (void)startRenderView{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
GAVFrame * m_pAVFrame ;
while (!_isReject){
if([[P2PClient sharedClient] gwplaybackState]!=PLAYBACK_STATE_PAUSE){
NSLog(@"P2PPlayingbackVC while 渲染监控画面");
if(fgGetVideoFrameToDisplay(&m_pAVFrame)){
//NSLog(@"\n回放的结构体:\n m_pAVFrame->width:%d\n m_pAVFrame->linesize[0]:%d \n m_pAVFrame->height:%d \n m_pAVFrame->linesize[0]:%d \n m_pAVFrame->pts:%llu ",
// m_pAVFrame->width,
// m_pAVFrame->linesize[0],
// m_pAVFrame->height,
// m_pAVFrame->linesize[0],
// m_pAVFrame->pts
// );
UInt64 u64TargetPTS = [[P2PClient sharedClient] playback_u64TargetPTS];
_theTimePlay = (m_pAVFrame->pts-[[P2PClient sharedClient] playback_startTime])/1000000;
_theTimeAll = [[P2PClient sharedClient] playback_totalTime]/1000000;
_thetimePlayStr=[self stringFromTime:_theTimePlay];
_thetimeAllStr=[self stringFromTime:_theTimeAll];
NSLog(@"_theTimePlay=%lld _theTimeAll==%lld",_theTimePlay,_theTimeAll);
if (_needUpdatePlayTimeShow) {
double sliderValue=(double)(_theTimePlay/(double)_theTimeAll);
if (isnan(sliderValue)) {
//若_theTimeAll=0,那么sliderValue值为nan,会引起崩溃
//所以加if判断
sliderValue=0;
}
NSLog(@"sliderValue=%.4f",sliderValue);
dispatch_async(dispatch_get_main_queue(), ^{
if (u64TargetPTS==0 || ((m_pAVFrame->pts >= u64TargetPTS) && (m_pAVFrame->pts-u64TargetPTS<1000000))) {
if (u64TargetPTS!=0) {
[self stSilence:NO];
}
[[P2PClient sharedClient] setPlayback_u64TargetPTS:0];
_labelPlayTheTime.text=_thetimePlayStr;
_labelPlayAllTime.text=_thetimeAllStr;
_labelPlaySpeedTime.text=_thetimePlayStr;
_sliderPlayProgress.value=sliderValue;
}
});
}
if (u64TargetPTS==0 || ((m_pAVFrame->pts >= u64TargetPTS) && (m_pAVFrame->pts-u64TargetPTS<1000000))) {
[self.remoteView render:m_pAVFrame];
}
vReleaseVideoFrame();
}
}
usleep(10000);
}
});
}
#pragma mark - 静音或者不静音
-(void)stSilence:(BOOL)flag{
if (flag) {
[[PAIOUnit sharedUnit] setMuteAudio:YES];
}else{
[[PAIOUnit sharedUnit] setMuteAudio:NO];
}
}
#pragma mark - 上一曲
-(void)preVideo{
if([[P2PClient sharedClient] getPlaybackCurrentFileIndex]==0){
[self.view makeToast:NSLocalizedString(@"no_previous_files", nil)];
}else{
[[P2PClient sharedClient] previous];
}
}
#pragma mark - 下一曲
-(void)nextVideo{
if([[P2PClient sharedClient] getPlaybackCurrentFileIndex]>=([[P2PClient sharedClient] getPlaybackFilesLength]-1)){
[self.view makeToast:NSLocalizedString(@"no_next_files", nil)];
}else{
[[P2PClient sharedClient] next];
}
}
#pragma mark - 快进
-(void)speedVideo{
if(_viewSpeed.hidden){
_viewSpeed.hidden = NO;
[[P2PClient sharedClient] fastBegin:_sliderPlayProgress.value *_theTimeAll];
}else{
[[P2PClient sharedClient] fastEnd:_sliderPlayProgress.value *_theTimeAll];
_viewSpeed.hidden = YES;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)500*NSEC_PER_MSEC), dispatch_get_main_queue(), ^{
if (_viewSpeed.hidden) {
[self playTimeTo:_sliderPlayProgress.value*_theTimeAll];
}
});
}
}
#pragma mark - 关闭播放
-(void)closeThePlay{
_isReject=YES;
//[[P2PClient sharedClient] playbackp2pHungUp];
[self quitFullController];
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 暂停或者播放
-(void)playOrPause{
vSetSupperDrop(NO);
if ([[P2PClient sharedClient] gwplaybackState]==PLAYBACK_STATE_PLAYING) {
_isPause=YES;
[[P2PClient sharedClient] setGwplaybackState:PLAYBACK_STATE_PAUSE];
[self stSilence:YES];
}else if([[P2PClient sharedClient] gwplaybackState]==PLAYBACK_STATE_PAUSE){
_isPause=NO;
[[P2PClient sharedClient] setGwplaybackState:PLAYBACK_STATE_PLAYING];
if (!_isSilence) {
[self stSilence:NO];
}
}else if([[P2PClient sharedClient] gwplaybackState]==PLAYBACK_STATE_STOP){
_isPause=YES;
[[P2PClient sharedClient] sendCommandType:USR_CMD_REMOTLY_PLAY_CTL
andOption:USR_CMD_OPTION_PLAY];
if (!_isSilence) {
[self stSilence:NO];
}
}
[self updatePauseButtonWithPause:_isPause];
}
#pragma mark - 滑块条事件
-(void)dropInsideEnd:(YSlider*)slider{
[self stSilence:YES];
[self playTimeTo:slider.value*_theTimeAll];
_needUpdatePlayTimeShow=YES;
_viewSpeed.hidden = YES;
}
-(void)dropCancel:(YSlider*)slider{
_needUpdatePlayTimeShow=YES;
}
-(void)dropInsideBegin:(YSlider*)slider{
_needUpdatePlayTimeShow=NO;
}
-(void)dropValueChange:(YSlider*)slider{
_thetimePlayStr=[self stringFromTime:slider.value*_theTimeAll];
_labelPlayTheTime.text=_thetimePlayStr;
}
#pragma mark - 全屏和不全屏的切换
-(void)fullScreenChange{
// BOOL is16B9 = [[P2PClient sharedClient] is16B9];
// if (!is16B9) {
// if (_isFullScreen) {
// _isFullScreen=NO;
// //开始切换为不全屏
// }else{
// _isFullScreen=YES;
// //开始切换为全屏
// }
// }
}
#pragma mark - 播放指定时间
-(void)playTimeTo:(NSTimeInterval)time{
[[P2PClient sharedClient] jump:time];
}
#pragma mark - 回调=视频回放挂断
-(void)P2PPlaybackReject:(NSDictionary *)info{
NSLog(@"回调=视频回放挂断");
//[self quitFullController];
//[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - 隐藏工具栏和显示工具栏
-(void)showToolsViewChange{
if (_viewBottomTools.top==(_theSizeOfScreen.height-_viewBottomTools.height)) {
[UIView animateWithDuration:0.26 animations:^{
_viewNaviBar.top=-_viewNaviBar.height;
_viewBottomTools.top=_theSizeOfScreen.height;
}];
}else{
[UIView animateWithDuration:0.26 animations:^{
_viewNaviBar.top=0;
_viewBottomTools.top=(_theSizeOfScreen.height-_viewBottomTools.height);
}];
}
}
#pragma mark - 隐藏任务栏
-(BOOL)prefersStatusBarHidden{
return YES;
}
#pragma mark - 按钮被单击
-(void)buttonBeClick:(FounderButton*)button{
if (button==_buttonPre) {
[self preVideo];
}
if (button==_buttonPause) {
[self playOrPause];
}
if (button==_buttonNext) {
[self nextVideo];
}
if (button==_buttonSpeed) {
[self speedVideo];
}
if (button==_buttonViewSpeed) {
[self speedVideo];
}
if (button==_buttonSilence) {
_isSilence=!_isSilence;
[self stSilence:_isSilence];
[self updateSilenceButtonWithPause:_isSilence];
}
if (button==_buttonBack) {
[self closeThePlay];
}
}
#pragma mark - 更新播放按钮
-(void)updatePauseButtonWithPause:(BOOL)pause{
if (!pause) {
[_buttonPause setImage:[UIImage imageNamed:@"FullPlay_Pause.png"] forState:UIControlStateNormal];
[_buttonPause setImage:[UIImage imageNamed:@"FullPlay_Pause_down.png"] forState:UIControlStateHighlighted];
}else{
[_buttonPause setImage:[UIImage imageNamed:@"FullPlay_Play.png"] forState:UIControlStateNormal];
[_buttonPause setImage:[UIImage imageNamed:@"FullPlay_Play_down.png"] forState:UIControlStateHighlighted];
}
}
#pragma mark - 更新静音按钮
-(void)updateSilenceButtonWithPause:(BOOL)silence{
if (silence) {
[_buttonSilence setImage:[UIImage imageNamed:@"FullPlay_Silence.png"] forState:UIControlStateNormal];
[_buttonSilence setImage:[UIImage imageNamed:@"FullPlay_Silence_down.png"] forState:UIControlStateHighlighted];
}else{
[_buttonSilence setImage:[UIImage imageNamed:@"FullPlay_NO_Silence.png"] forState:UIControlStateNormal];
[_buttonSilence setImage:[UIImage imageNamed:@"FullPlay_NO_Silence_down.png"] forState:UIControlStateHighlighted];
}
}
#pragma mark - 缩放手势(鱼眼设备)
-(void)onPinchToZoom:(UIPinchGestureRecognizer*)sender {
//鱼眼设备
// zoom in/out
if(sender.state == UIGestureRecognizerStateBegan){
}
else if(sender.state == UIGestureRecognizerStateEnded){
}else if(sender.state == UIGestureRecognizerStateChanged){
float fscale = [sender scale];
if(fscale>1)
{
//[_remoteView setZoomInOpenGLView];
}
else{
//[_remoteView setZoomOutOpenGLView];
}
}
}
-(void)panEvent:(UIPanGestureRecognizer*)sender{
if(sender.state == UIGestureRecognizerStateBegan){
//[_remoteView setKeyStatusInOpenGLView:0];//KEY_DOWN
}
else if(sender.state == UIGestureRecognizerStateEnded){
// [_remoteView setKeyStatusInOpenGLView:1];//KEY_UP
// [_remoteView setFlingInOpenGLViewX:[sender locationInView:_remoteView].x - self.swipeLastPos.x Y:[sender locationInView:_remoteView].y - self.swipeLastPos.y];
self.swipeLastPos = CGPointMake(0.0, 0.0);
}
else if(sender.state == UIGestureRecognizerStateChanged){
CGPoint point = [sender locationInView:_remoteView];
if(self.swipeLastPos.x != 0 && self.swipeLastPos.y != 0){
float x0, y0;
x0 = point.x - self.swipeLastPos.x;
y0 = point.y - self.swipeLastPos.y;
//[_remoteView setMoveStepInOpenGLViewX:point.x Y:point.y dX:x0 dY:y0];
}
self.swipeLastPos = point;
}
else if(sender.state == UIGestureRecognizerStateRecognized){
}
}
#pragma mark - 屏幕Autorotate
-(BOOL)shouldAutorotate{
return YES;
}
#pragma mark - 屏幕旋转
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (toInterfaceOrientation == UIInterfaceOrientationPortrait)
{
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
}
}
#pragma mark 支持哪些方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeRight;
}
-(void)quitFullController
{
//设置竖屏
[AppDelegate sharedDefault].canFullScreen = NO;
static int isFullScreen = 1; // 3 == 全屏 1 == 竖屏
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
NSLog(@"self.interfaceOrientation%ld",(long)UIDeviceOrientationPortrait);
//NSNumber *numb=[NSNumber numberWithInteger:UIDeviceOrientationPortrait];
//[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
// withObject:numb];
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
NSLog(@"-%d-",isFullScreen);
[invocation setArgument:&isFullScreen atIndex:2];
[invocation invoke];
}
}
@end