iPhone上实现流媒体播放器

来源:互联网 发布:mac上的网络游戏 编辑:程序博客网 时间:2024/04/30 04:05

      首先,获取到视频的截图

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewCell *movieCell = [DataTable dequeueReusableCellWithIdentifier:@"movieCell"];    if (movieCell==nil) {        movieCell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"movieCell"]autorelease];    }    NSString *linkStr = [linkArray objectAtIndex:indexPath.row];    movieCell.textLabel.text = linkStr;    MPMoviePlayerController *movieController = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:linkStr]];    [movieController requestThumbnailImagesAtTimes:[NSArray arrayWithObject:[NSNumber numberWithDouble:0]] timeOption:MPMovieTimeOptionNearestKeyFrame];    [[NSNotificationCenter defaultCenter]addObserver:self                                            selector:@selector(movieThumbnailLoadComplete:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:movieController];    return movieCell;}-(void)movieThumbnailLoadComplete:(NSNotification*)notification{    NSDictionary *userInfo = [notification userInfo];    NSLog(@"userInfo:%@",userInfo);NSNumber *timecode =     [userInfo objectForKey: @"MPMoviePlayerThumbnailTimeKey"];UIImage *image =     [userInfo objectForKey: @"MPMoviePlayerThumbnailImageKey"];}


    点击后,启动播放

-(void)initPlayer{    //显示loadingView    [loadingView show:YES];    //使用playerItem获取视频的信息,当前播放时间,总时间等    AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:movieURL];    //player是视频播放的控制器,可以用来快进播放,暂停等    AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];    [moviePlayeView setPlayer:player];    [moviePlayeView.player play];    //计算视频总时间    CMTime totalTime = playerItem.duration;    //因为slider的值是小数,要转成float,当前时间和总时间相除才能得到小数,因为5/10=0    totalMovieDuration = (CGFloat)totalTime.value/totalTime.timescale;    //NSLog(@"totalMovieDuration:%f",totalMovieDuration);    //在totalTimeLabel上显示总时间    totalTimeLabel.text = [self convertMovieTimeToText:totalMovieDuration];        //检测视频加载状态,加载完成隐藏loadingView    [moviePlayeView.player.currentItem addObserver:self                                        forKeyPath:@"status"                                            options:NSKeyValueObservingOptionNew                                           context:nil];    //添加视频播放完成的notifation    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(moviePlayDidEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:moviePlayeView.player.currentItem];}


    上述代码来源:https://github.com/yuyi012/VideoStreamDemo2

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 想把衣服换颜色怎么办 衣服用84洗坏了怎么办 衣服用84洗花了怎么办 衣服用84洗黄了怎么办 白色衣服用84漂黄了怎么办 84把衣服泡黄了怎么办 84把衣服洗花了怎么办 衣服用84洗掉色怎么办 被84褪色的衣服怎么办 衣服被84烧红了怎么办 84溅到衣服上边怎么办 84把衣服泡花了怎么办 衣服颜色洗旧了怎么办 蒙版画笔用不了怎么办 眼睛小血管破裂出血怎么办 雅漾喷头坏了怎么办 一夜都是浅睡眠怎么办 注塑机合不了膜怎么办 吸了塑料烧焦味怎么办 热熔的管漏水怎么办 45岁了月经不来怎么办 吃了芒果身上痒怎么办 10个月宝宝上火怎么办 1个月的宝宝上火怎么办 2个月的婴儿上火怎么办 1岁宝宝不吃奶粉怎么办 奶水不够宝宝又不吃奶瓶怎么办 13岁脸上长粉刺怎么办 脸敷面膜过敏了怎么办 婴儿面膜是假的怎么办 一贴面膜就过敏怎么办 一敷面膜就过敏怎么办 敷了面膜后过敏怎么办 脸做面膜过敏了怎么办 二十几年的疤痕怎么办 三星c5听筒坏了怎么办 胖子减肥后皮肤松弛怎么办 小婴儿脸上长癣怎么办 痘痘里面有脓怎么办 牛仔外套买大了怎么办 脸上痘印红红的怎么办