Introduction to several ways of iOS midrange video playback

Source: Internet
Author: User

In iOS design, audio and video playback is usually involved in most of the design process, so it is important to clearly understand and use the audio and video playback structure, the following are several commonly used audio and video playback methods:

(a) using the system-provided player, to play music that is less than 30s in length, usually in. caf,.aif,.wav format:

Create a System Playback object:

  Audioservicescreatesystemsoundid (Cfurlref  infileurl, Systemsoundid  *outsystemsoundid);
Play System ring tone
Audioservicesplaysystemsound (ksystemsoundid_vibrate); For vibration-enabled devices, you can set the vibration state 
Audioservicesdisposesystemsoundid (Self.soundsystemid);//non-arc conditions, after the completion of the function, the need for manual destruction (ii)

(ii) Use Avaudioplayer to play a file or a music file in the cache:

It is characterized by: can play any length of time, the file address in the local file or cache, can realize the loop play, can play multiple songs simultaneously and realize synchronization, can achieve fine control.

Nsurl *soudfileurl = [[NSBundle mainbundle] Urlforresource:@"Qian female Ghost"Withextension:@"mp3"];//creates an Error object, which is defined here as a pointer object, because the parameters required by the API interface are outgoing parameters and pointers.Nserror *error =Nil; Self.audioplayer= [[Avaudioplayer alloc] Initwithcontentsofurl:soudfileurl error:&ERROR]; Self.audioPlayer.numberOfLoops=2;//if the error value is not empty, it means that the initialization of the Audioplayer object fails, and the failure processing is required    if(Error! =Nil) {NSLog (@"INIT audioplay Faile. error:%@", error);    } [Self.audioplayer Preparetoplay]; [Self.audioplayer play];

(iii) Play audio files with Avplayer implementation

The biggest difference between playing with the above is that he can play local music and remote music, which is network music.

@" http://zhangmenshiting.baidu.com/data2/music/119358766/11794803954000128.mp3?xcode= 055849B238EF1D51897273D786699F632C0420DE8B6192FF"*soundurl =*player= [[Avplayer Alloc] Initwithurl:soundurl];

(iv) video files that use MPMoviePlayerController to play video local or network streams

    Nsurl *myurl = [[NSBundle mainbundle] Urlforresource:@ "s6t9u6014" withextension:@ "  mp4"];     = [[MPMoviePlayerController alloc] initwithcontenturl:myurl];    [Self.player Preparetoplay];    [Self.view AddSubview:self.player.view];    [Self.player.view setFrame:self.view.bounds];    [Self.player play];
(v) Use Mpmovieplayerviewcontroller to play local or network streaming video files
Nsurl *myurl = [Nsurl urlwithstring:@ "http://v.youku.com/player/getRealM3U8/vid/XNzA3NzY3MDgw/type/ video.m3u8"*player =    = uimodaltransitionstylecoververtical;[ Self Presentviewcontroller:player animated:yes completion:nil];

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.