<Graphic images, animations, multimedia> Reading Notes-Videos

Source: Internet
Author: User

1. AVI file

Avi is the abbreviation of audio/video interleaved. It is a digital audio and video file format developed by Microsoft to comply with Riff file specifications, it is a file format that combines audio and video synchronization. It adopts a Lossy Compression Method for video files.


2. WMV file

WMV is also a streaming media format launched by Microsoft. With the same video quality, the WMV format is very small, so it is suitable for online playback and transmission.


3. rmvb File

Rmvb is a video file format. In rmvb, VB indicates that it breaks the average bit rate of compression and reduces the bit rate on the static screen to optimize the bit rate on the entire video, improve efficiency and save resources. the biggest feature of rmvb is its small size while ensuring file clarity.


4.3gp File

3GP is a video encoding format for 3G streaming media. It is developed to meet the high transmission speed of 3G networks and is also a video format in mobile phones. 3GP allows users to send a large amount of data to the mobile phone network, so as to clearly transmit large files, is the new standard format for mobile devices. the advantage is that the file is small in size and highly mobile, and is suitable for mobile devices. the disadvantage is poor compatibility on PC. the support software is small, and the playback quality is poor, the number of frames is low, and the AVI transfer is much worse.


5. mov file

MoV is an audio and video file format developed by Apple. It is used to store common digital media types. moV format files are organized in the form of tracks. A mov format file structure can contain multiple tracks, mov format files, the picture effect is slightly better than Avi cities.


6. MP4 files

MP4 is a multimedia file format using MPEG-4, the file suffix is MP4, using h264 decoding.


7. m4v File

M4v is a standard video file format used by IOS devices, working with this format based on the second edition of MPEG-4 Encoding


About mpmoveplayercontroller


<p class="p1"><span class="s1">_moviePlayer</span><span class="s2">.</span><span class="s3">scalingMode</span><span class="s2"> = </span>MPMovieScalingModeAspectFit<span class="s2">;</span></p>typedef NS_ENUM(NSInteger, MPMovieScalingMode) {    MPMovieScalingModeNone,       // 原始尺寸    MPMovieScalingModeAspectFit,  // 保持原始高宽比缩放视频,使其填充一个方向,另一个方向会有黑边    MPMovieScalingModeAspectFill, // 保持原始高宽比缩放视频,使其填充两个方向,一个方向可能超出屏幕,则会切除    MPMovieScalingModeFill        // 两个方向刚好填充两边,不考虑保持原始的高宽比缩放视频,结果有可能会高宽比例失真};


_moviePlayer.controlStyle = MPMovieControlStyleDefault;typedef NS_ENUM(NSInteger, MPMovieControlStyle) {    MPMovieControlStyleNone,       // 没有播放控制控件,适合与游戏等应用过度界面或片尾视频等    MPMovieControlStyleEmbedded,   // 嵌入风格的播放控制控件,没有Done按钮    MPMovieControlStyleFullscreen, // 全屏播放,有播放进度,Done按钮,快进等控件        MPMovieControlStyleDefault = MPMovieControlStyleEmbedded //默认风格,没有Done按钮};

Note: to add mpmoveplayercontroller to view, add a _ movieplayer. view, because it is not a view or controller, but inherits nsobject, and also needs to [_ movieplayersetfullscreen: yesanimated: Yes]; full screen display. remember removefromsuperview after playing


<p class="p1"><span class="s1">_moviePlayer</span><span class="s2">.</span>playbackState</p>typedef NS_ENUM(NSInteger, MPMoviePlaybackState) {    MPMoviePlaybackStateStopped, //停止状态    MPMoviePlaybackStatePlaying, //播放状态    MPMoviePlaybackStatePaused,  //暂停状态    MPMoviePlaybackStateInterrupted, //临时中断状态    MPMoviePlaybackStateSeekingForward, //向前跳过状态    MPMoviePlaybackStateSeekingBackward //向后跳过状态};


Some records under the avfoundation framework


Avplayer is the core class required for video playback. It has four constructor methods, which can be constructed through nsurl or avplayeritem. When presenting a video, you need to put avplayer into avplayerlayer, add the avplayerlayer object to the layer of the current view.


Avqueueplayer: If you want to play multiple videos, you can use the avqueueplayer object. It can contain multiple avplayeritem objects.


Avplayerlayer: Specifies the video playback layer object. It must be added to the current view.


Avasset indicates an abstract media, including the title, file size, and so on. Each avasset is composed of multiple tracks. Each track can be an audio channel or video channel.


Avurlasset is the specific implementation class of avasset. You can use nsurl to initialize avurlasset.


Avplayeritem indicates the status of an avasset. You can use it to observe the video playback status.



Avplayer is a simple player.

#import "ViewController.h"#import <AVFoundation/AVFoundation.h>@interface ViewController (){    id timeObserver;//自定义监听着    BOOL isPlaying;//判断是否播放    }- (IBAction)play:(id)sender;- (IBAction)seek:(id)sender;@property (weak, nonatomic) IBOutlet UISlider *slider;@property (weak, nonatomic) IBOutlet UIToolbar *toolBar;@property (nonatomic,weak) AVPlayer *avPlayer;@property (nonatomic,weak) AVPlayerLayer *layer;@property (nonatomic,strong) AVPlayerItem *playerItem;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"YY" ofType:@"mp4"];    NSURL *fileURL = [NSURL fileURLWithPath:filepath];        //具体实现类    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:fileURL options:nil];        //代表一个AVAsset状态,可以使用他观察到视频播放状态    self.playerItem = [AVPlayerItem playerItemWithAsset:asset];        //播放视频需要的核心类    self.avPlayer = [AVPlayer playerWithPlayerItem: self.playerItem ];        self.layer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];        float scale = 1.776;        self.layer.frame = CGRectMake(0, -350,                                  self.view.frame.size.width * scale,                                  self.view.frame.size.height * scale);        //添加到当前视图的图层上    [self.view.layer insertSublayer:self.layer atIndex:0];        double duration = CMTimeGetSeconds(asset.duration);        self.slider.maximumValue =  duration;    self.slider.minimumValue  = 0.0;        isPlaying = NO;        }- (void)didReceiveMemoryWarning{    [super didReceiveMemoryWarning];}- (IBAction)play:(id)sender {        UIBarButtonItem *item1;        if (!isPlaying) {                [self addObserver];        [self.avPlayer seekToTime:kCMTimeZero];        [self.avPlayer play];                isPlaying = YES;        item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause                                                              target:self                                                              action:@selector(play:)];                    } else  {        isPlaying = NO;        item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay                                                              target:self                                                              action:@selector(play:)];                [self.avPlayer pause];    }        NSMutableArray *items = [[NSMutableArray alloc] initWithArray:[self.toolBar items]];    [items replaceObjectAtIndex:0 withObject:item1];        [self.toolBar setItems:items];    }- (IBAction)seek:(id)sender {    float value = [self.slider value];    [self.avPlayer seekToTime:CMTimeMakeWithSeconds(value, 10)];}-(void)addObserver{        if (timeObserver == nil) {                //播放完成的通知        [[NSNotificationCenter defaultCenter] addObserver:self                                                 selector:@selector(playerItemDidReachEnd:)                                                     name:AVPlayerItemDidPlayToEndTimeNotification                                                   object:self.playerItem];                //创建AVPlayer定时器事件观察者对象        timeObserver = [self.avPlayer addPeriodicTimeObserverForInterval:CMTimeMake(1, 10)                                                                   queue:dispatch_get_main_queue()                                                              usingBlock:^(CMTime time) {                                                                  float duration = CMTimeGetSeconds(self.avPlayer.currentTime);                                                                  NSLog(@"duration = %f",duration);                                                                  self.slider.value = duration;                                                              }                        ];            }    }- (void) playerItemDidReachEnd:(NSNotification*) aNotification{    NSLog(@"播放完成");    if (timeObserver) {        [self.avPlayer removeTimeObserver:timeObserver];                timeObserver = nil;        self.slider.value = 0.0;        isPlaying = NO;                [[NSNotificationCenter defaultCenter] removeObserver:self                                                        name:AVPlayerItemDidPlayToEndTimeNotification                                                      object:nil];                        UIBarButtonItem* item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay                                                                               target:self                                                                               action:@selector(play:)];                                                        NSMutableArray *items = [[NSMutableArray alloc] initWithArray:[self.toolBar items]];        [items replaceObjectAtIndex:0 withObject:item1];                [self.toolBar setItems:items];    }    }



Original book: http://item.jd.com/11522516.html


<Graphic images, animations, multimedia> Reading Notes-Videos

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.