设为首页 - 加入收藏 焦点技术网
热搜:java
当前位置:首页 >

视频播放

2016-04-05 21:50:21.0 java  
导读:本文啦啦啦啦啦123给大家介绍 视频播放。#import "MovieViewController.h" #import <AVKit/AVKit.h>。。。
#import "MovieViewController.h"
#import <AVKit/AVKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MovieViewController ()

@end

@implementation MovieViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupVideoPlayback];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    if ([self isPlaying])
    {
        [self stopPlayback];
    }
}
-(void)stopPlayback
{
    [self.player setRate:0];
    self.player = nil;
}
-(BOOL)isPlaying
{
    if (self.player.currentItem && self.player.rate > 0)
    {
        return YES;
    }
    return NO;
}
-(void)setupVideoPlayback
{
    NSURL *url          = [[NSBundle mainBundle] URLForResource:@"movie" withExtension:@"mp4"];
    AVURLAsset *asset   = [AVURLAsset URLAssetWithURL:url options:nil];
    AVPlayerItem *item  = [AVPlayerItem playerItemWithAsset:asset];
    self.player         = [AVPlayer playerWithPlayerItem:item];
    [self.player seekToTime:kCMTimeZero];
    [self.player play];
}
#import "MovieViewController.h"

@interface MovieViewController ()

@end

@implementation MovieViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupVideoPlayback];
}
-(void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    if ([self isPlaying])
    {
        [self stopPlayback];
    }
}
-(void)stopPlayback
{
    [self.player setRate:0];
    self.player = nil;
}
-(BOOL)isPlaying
{
    if (self.player.currentItem && self.player.rate > 0)
    {
        return YES;
    }
    return NO;
}
-(void)setupVideoPlayback
{
    NSURL *url          = [[NSBundle mainBundle] URLForResource:@"movie" withExtension:@"mp4"];
    AVURLAsset *asset   = [AVURLAsset URLAssetWithURL:url options:nil];
    AVPlayerItem *item  = [AVPlayerItem playerItemWithAsset:asset];
    self.player         = [AVPlayer playerWithPlayerItem:item];
    [self.player seekToTime:kCMTimeZero];
    [self.player play];
}

(编辑: 啦啦啦啦啦123)

网友评论
相关文章