RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
简单的播放界面-创新互联

//

成都创新互联公司是一家专注于成都网站制作、网站建设与策划设计,长安网站建设哪家好?成都创新互联公司做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:长安等地区。长安做网站价格咨询:18980820575

//  MoviePlayerView.m

//  Project1--Movie

//

//  Created by imac on 15/9/4.

//  Copyright (c) 2015年 Hong. All rights reserved.

//

#import "MoviePlayerView.h"

#import "UIView+ViewController.h"

@implementation MoviePlayerView

- (void)awakeFromNib{

  //[super awakeFromNib];

  _moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:nil];

  //播放界面

  _moviePlayer.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

  //关闭子视图的自适应

  // _moviePlayer.backgroundView.autoresizesSubviews = NO;

  _moviePlayer.view.frame = self.bgView.bounds;

  _moviePlayer.controlStyle = MPMovieControlStyleNone;

  [_moviePlayer play];

  [self.bgView insertSubview:_moviePlayer.view atIndex:0];

//   //创建音量滑动条

//   _volumnSlider = [[MPVolumeView alloc]initWithFrame:CGRectMake(-75.f, 150.f, 160.f, 30.f)];

//   //!!MPVolumnView只有在真机才显示

//   _volumnSlider.transform = CGAffineTransformMakeRotation(M_PI_2);

//   _volumnSlider.layer.anchorPoint = CGPointMake(0, 0);

//

//   [self.volumnView addSubview:_volumnSlider];

  //自定义滑动条

  _volumeSlider = [[UISlider alloc]initWithFrame:CGRectMake(-35.f, 50.f, 110.f, 30.f)];

  _volumeSlider.transform = CGAffineTransformMakeRotation(-M_PI_2);

  _volumeSlider.maximumValue = 10;

  _volumeSlider.minimumValue = 0;

  _volumeSlider.value = 0;

  //音量条的滑块样式

  [_volumeSlider setThumbImage:[UIImage p_w_picpathNamed:@"point"] forState:UIControlStateNormal];

  [_volumeView addSubview:_volumeSlider];

  [_volumeSlider addTarget:self action:@selector(volumeChange:) forControlEvents:UIControlEventValueChanged];

  //进度条上滑块样式

  [_processSlider setThumbImage:[UIImage p_w_picpathNamed:@"progress_blue_bar@2x"] forState:UIControlStateNormal];

  [_processSlider setThumbImage:[UIImage p_w_picpathNamed:@"point"] forState:UIControlStateHighlighted];

  //添加通知

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(duration) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(createProcessTimer) name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:nil];

  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

  //如果没有URl就播放本地视频

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];

  _moviePlayer.contentURL = [NSURL fileURLWithPath:filePath];

  [_moviePlayer play];

  //缩放按钮

  [_zoomBtn setImage:[UIImage p_w_picpathNamed:@"zoomin"] forState:UIControlStateNormal];

  [_zoomBtn setImage:[UIImage p_w_picpathNamed:@"zoomout"] forState:UIControlStateSelected];

  //锁定按钮

  [_lockBtn setTitle:@"Lock" forState:UIControlStateNormal];

  [_lockBtn setTitle:@"Unlock" forState:UIControlStateSelected];

  _leftTimeLabel.text = @"00:00:00";

}

#pragma mark--layoutSubviews

- (void)layoutSubviews{

  //获取屏幕方向

  UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

  if (orientation == UIInterfaceOrientationPortrait) {

    self.bgView.size = CGSizeMake(kWidth, 250.f);

    self.frame = self.bgView.bounds;

  }else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){

    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {

      self.bgView.size = CGSizeMake(kWidth, kHeight);

    }else{

      self.bgView.size = CGSizeMake(kHeight, kHeight);

    }

    self.frame = self.bgView.bounds;

  }else{

    NSLog(@"test");

  }

}

#pragma mark--Notification

- (void)duration{

  //视频时长

  _processSlider.maximumValue = _moviePlayer.duration;

  _rightTimeLabel.text = [self calculateTime:_moviePlayer.duration];

}

- (void)createProcessTimer{

  _processTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(setProcess:) userInfo:nil repeats:YES];

}

- (void)movieFinish{

  [_processTimer invalidate];

  _processTimer = nil;

}

- (void)volumeChange:(UISlider *)slider{

  //[MPMusicPlayerController applicationMusicPlayer].volume = slider.value;

}

//设置进度

- (void)setProcess:(NSTimer *)timer{

  _second++;

  self.leftTimeLabel.text = [self calculateTime:_second];

  [_processSlider setValue:_second animated:YES];

}

- (NSString *)calculateTime:(NSTimeInterval)time{

  //小时

  int h = time / 3600;

  int retain = (int)time % 3600;

  //分钟

  int m = retain / 60;

  //秒

  int s = retain % 60;

  return [NSString stringWithFormat:@"%02d:%02d:%02d",h,m,s];

}

//- (void)setUrl:(NSString *)url{

//   _url = url;

//

//   if (url.length > 0) {

//     _moviePlayer.contentURL = [NSURL URLWithString:_url];

//     _moviePlayer.contentURL = [NSURL URLWithString:url];

//     [_moviePlayer play];

//

//   }else{

//     //如果没有URl就播放本地视频

//     NSString *filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];

//     _moviePlayer.contentURL = [NSURL fileURLWithPath:filePath];

//     [_moviePlayer play];

//   }

//}

#pragma mark-Touch Method

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

  self.upView.hidden = !self.upView.hidden;

  self.volumeView.hidden = !self.volumeView.hidden;

  self.bottomView.hidden = !self.bottomView.hidden;

}

- (IBAction)lockClick:(UIButton *)sender {

  sender.selected = !sender.selected;

}

- (IBAction)playClick:(UIButton *)sender {

  [_moviePlayer pause];

  sender.selected = !sender.selected;

  if (sender.selected) {

    [sender setImage:[UIImage p_w_picpathNamed:@"play"] forState:UIControlStateNormal];

    [_moviePlayer pause];

    [_processTimer invalidate];

    _processTimer = nil;

  }else{

    [sender setImage:[UIImage p_w_picpathNamed:@"pause"] forState:UIControlStateNormal];

    [_moviePlayer play];

    [self createProcessTimer];

  }

}

//进度条滑动触发事件

- (IBAction)processChange:(UISlider *)sender {

  self.leftTimeLabel.text = [self calculateTime:sender.value];

  //调整播放进度

  [_moviePlayer setCurrentPlaybackTime:sender.value];

}

- (IBAction)zoomClick:(UIButton *)sender {

  sender.selected = !sender.selected;

  if (sender.selected) {

//     self.bgView.transform = CGAffineTransformMakeRotation(-M_PI_2);

    //self.bgView.origin = CGPointMake(0 , 300);

    //self.bgView.transform = CGAffineTransformMakeScale(kHeight/self.bgView.size.width, kWidth/self.bgView.size.height);

    //self.bgView.frame =[UIScreen mainScreen].bounds;

//     self.bgView.transform = CGAffineTransformMakeTranslation(0, (kHeight-_moviePlayer.view.size.height)/2);

//     self.viewController.view.backgroundColor = [UIColor blackColor];

  }else{

//     self.bgView.transform = CGAffineTransformMakeTranslation(0, 0);

//     self.viewController.view.backgroundColor = [UIColor whiteColor];

  }

}

- (IBAction)columeClick:(UIButton *)sender {

  sender.selected = !sender.selected;

  if (sender.selected) {

    [sender setImage:[UIImage p_w_picpathNamed:@"volume_mute"] forState:UIControlStateNormal];

    _volumeSlider.value = 0;

  }else{

    [sender setImage:[UIImage p_w_picpathNamed:@"volume.png"] forState:UIControlStateNormal];

  }

}

@end

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:简单的播放界面-创新互联
分享地址:http://lswzjz.com/article/dhgecj.html