iOS Development Multimedia API (1)

Source: Internet
Author: User
Tags notification center

This article reprinted to http://mobile.51cto.com/iphone-423224.htm

The video format can be divided into two categories, which are suitable for local broadcast video and network streaming image video which is suitable for playing in the network. Although the latter may not be good in the quality of the playback stability and playback screen, but the wide spread of network streaming video image is widely used in video-on-demand, network demonstrations, distance education, network video advertising and other Internet Information services.

AD:2014WOT Global Software Technology Summit Beijing Station course video release

Play Video

Video File Introduction

The video format can be divided into two categories, which are suitable for local broadcast video and network streaming image video which is suitable for playing in the network. Although the latter may not be good in the quality of the playback stability and playback screen, but the wide spread of network streaming video image is widely used in video-on-demand, network demonstrations, distance education, network video advertising and other Internet Information services.

Video files for mobile devices

3GP,3GP is a 3G streaming video encoding format, mainly in order to match the high transmission speed of 3G network developed, but also the most common in the mobile phone video format. Video MP4 format, in addition to support the MP3 has the music playback function, but also has a powerful MPEG-4 video playback ability.

mov format files are also supported in the iphone.

iOS play Video

The IOS SDK provides a very easy way to play video, providing the Mpmovieplayerviewcontroller class as a development use, before the iOS4 version is MPMoviePlayerController.

It is forbidden to use the private API to play video in the iphone development specification, so the control of the playback screen is available on the iphone, and we have no other choice. What we can do:

Load the video in the URL

Play, pause video

User control behavior and zoom mode

Generate notifications

Video playback Cases

Add Mediaplayer.framework

MoviePlayerViewController.h

    1. #import <MediaPlayer/MediaPlayer.h>
    2. @interface Movieplayerviewcontroller:uiviewcontroller {
    3. Mpmovieplayerviewcontroller * Movieplayerview;
    4. }
    5. @property (nonatomic, retain) Mpmovieplayerviewcontroller * Movieplayerview;
    6. -(Ibaction) Playmovie: (ID) sender;
    7. -(void) Playingdone;
    8. @end

How to load and unload m files

    1. -(void) Viewdidload {
    2. [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (playingdone) Name: Mpmovieplayerplaybackdidfinishnotification Object:nil];
    3. }
    4. -(void) Dealloc {
    5. [[Nsnotificationcenter Defaultcenter] removeobserver:self];
    6. [Movieplayerview release];
    7. [Super Dealloc];
    8. }

Mpmovieplayerviewcontroller provides notification of state changes and other events during playback. In Viewdidload registered a playback complete notification, the commonly used notifications are:

Mpmovieplayerplaybackdidfinishnotification notifies the receiver that the playback is complete.

Mpmovieplayerscalingmodedidchangenotification change the size of the movie.

Mpmovieplayercontentpreloaddidfinishnotification indicates preprocessing and completion, ready to start playing the movie.

[[Nsnotificationcenter Defaultcenter] in the Dealloc method

Removeobserver:self]; movie playback complete to unregister the notification.

Play Events

  1. -(Ibaction) Playmovie: (ID) Sender {
  2. Movieplayerview = [[Mpmovieplayerviewcontroller alloc]
  3. Initwithcontenturl:[nsurl Fileurlwithpath:[[nsbundle Mainbundle]
  4. pathforresource:@"short" oftype:@"3gp"];
  5. MoviePlayerView.moviePlayer.controlStyle = Mpmoviecontrolstylefullscreen;
  6. MoviePlayerView.moviePlayer.scalingMode = Mpmoviescalingmodeaspectfit;
  7. //Mpmoviecontrolstylenone
  8. //mpmoviecontrolstyleembedded
  9. //mpmoviecontrolstyledefault
  10. //[movieplayer Play];
  11. //view to add a video on the current view
  12. [[[UIApplication sharedapplication] Keywindow] addSubview:moviePlayerView.view];
  13. }

Video files can play resource catalogs, sandbox catalogs, and network playback. In this example we use the Resource directory.

The Movieplayerview.movieplayer property is a MPMoviePlayerController type, and it has controlstyle properties

You can control the playback behavior, which has the following values:

Mpmoviecontrolstylefullscreen

Mpmoviecontrolstylenone No playback controls

mpmoviecontrolstyleembedded

Mpmoviecontrolstyledefault

The MPMoviePlayerController class also has the Scalingmode property to control the size of the movie, which takes the following values:

Mpmoviescalingmodenone Original Size

Mpmoviescalingmodeaspectfit Zoom to a fill direction

Mpmoviescalingmodeaspectfill may be partially removed on both sides of the fill

Mpmoviescalingmodefill fills may change proportions on both sides

Play complete

    1. -(void) Playingdone {
    2. NSLog (@"play complete");
    3. [Movieplayerview.view Removefromsuperview];
    4. [Movieplayerview release];
    5. Movieplayerview = nil;
    6. }

The Playingdone method is called when the movie playback is complete, because we register the method in the notification center.

Playback must be done to remove the playback view so that the previous screen can be obtained.

12.2 Playing Audio

12.2.1 Audio File Introduction

There are two main types of audio file formats:

Lossless formats, such as Wav,pcm,tta,flac,au,ape,tak,wavpack (WV), CAF

Lossy formats, such as Mp3,windows Media Audio (WMA), Ogg Vorbis (OGG), AAC

Moving audio files

As a mobile device audio file should be in principle relatively small, general format:

WAV, because lossless compression effect is best.

MP3, lossy compression, the file is relatively small, because the removal of the human can not sense the sound, the effect is very good. This is the current common format.

AAC, compression ratio is larger, smaller than the MP3 file.

The CAF (Core Audio format) is an apple-only lossless compression format.

12.2.2 Core Audio

Advanced API, easy to use

The System sound API – plays short sounds, warning tones, and so on.

Avfoundation can play long-time sound, easy to use.

Low-level API that gives you more control over your audio

Audio toolbox– is fully controlled for recording, playback and streaming.

openal– plays stereo, often used in games.

12.2.3 System Sound API

The System sound can play "short" sounds, and the so-called short sound is within 5 seconds. No loop, no sound control, instant playback.

Playback format Restrictions:

Linear PCM and IMA4

. CAF. AIF or. wav

Play "Short Sound"

Playing "short sound" is primarily a two-step process:

Register Sound

    1. Audioservicescreatesystemsoundid ((cfurlref) FileURL, &myid);

Play sound

    1. Audioservicesplaysystemsound (MyID);

Listener Completion Event Method

    1. Audioservicesaddsystemsoundcompletion

Clear Play sound ID

    1. Systemsoundid MyID;
    2. Audioservicesdisposesystemsoundid (MyID);

Vibration

You can also vibrate your iphone with the system sound API, but ipod touch doesn't vibrate.

Vibrations can be achieved by specifying a special system sound id--ksystemsoundid_vibrate.

Audioservicesplaysystemsound (ksystemsoundid_vibrate);

iOS Development Multimedia API (1)

Related Article

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.