1> audio playback
Ø dependent frameworks: avfoundation and audiotoolbox ø play long Music: avaudioplayer ø play short sound: load the audio file to generate systemsoundid ø recording: avaudiorecord
2> video playback
Differences between the two video playback classes:
Mpmovieplayercontroller inherits from nsobject;
Mpmovieplayerviewcontroller inherits from uiviewcontroller, which encapsulates an mpmovieplayercontroller. Easy to use:
// Load the video resource nsstring * urlstring = [[nsbundle mainbundle] pathforresource: @ "sample_itunes" oftype: @ "mov"]; nsurl * url = [nsurl fileurlwithpath: urlstring]; // create a player _ player = [[mpmovieplayercontroller alloc] initwithcontenturl: url]; // set the size of _ player. view. frame = self. view. bounds; _ player. view. autoresizingmask = uiviewautoresizingflexiblewidth | uiviewautoresizingflexibleheight; // Add it to the Controller view [self. view addsubview: _ player. view]; // play [_ player play];
// Listen for changes in the playback status [[nsnotificationcenter defacenter center] addobserver: Self selector: @ selector (videostatechange)
Name: mpmovieplayerplaybackstatedidchangenotification object: _ Player]; // listen to the player end full screen [[nsicationicationcenter defacenter center] addobserver: Self selector: @ selector (exitfullscreen)
Name: mpmovieplayerdidexitfullscreennotification object: _ Player];
Other attributes and methods:
Whether to automatically play @ property (nonatomic) bool shouldautoplay; full screen display @ property (nonatomic, Getter = isfullscreen) bool fullscreen;-(void) setfullscreen :( bool) fullscreen animated :( bool) animated; capture the image in the video-(void) requestthumbnailimagesattimes :( nsarray *) playbacktimes timeoption :( mpmovietimeoption) option;
Complete code: Video Playback
Appendix:
1> Add images to the system album
Uiimagewritetosavedphotosalbum ([uiimage imagenamed: @ "default.png"], self, @ selector (image: didfinishsavingwitherror: contextinfo :), null );
2> uisavevideoatpathtosavedphotosalbum Function