| 简介 
                          最新的设备 音频和视频是很常见的。在 IOS 中分别在 AVFoundation.framework 和 MediaPlayer.framewor 支持帮助下可实现操作。 
                          涉及的步骤 1. 创建一个简单的应用程序。 2. 选择项目文件,选择目标,然后我们添加 AVFoundation.framework 和 MediaPlayer.framework. 3. 添加两个按钮ViewController.xib的和播放音频和视频分别创建一个动作。 4. 更新 ViewController.h 文件内容如下: 
                          
                            | #import <UIKit/UIKit.h>#import <AVFoundation/AVFoundation.h>
 #import <MediaPlayer/MediaPlayer.h>
 @interface ViewController : UIViewController{
 AVAudioPlayer *audioPlayer;
 MPMoviePlayerViewController *moviePlayer;
 
 }
 -(IBAction)playAudio:(id)sender;
 -(IBAction)playVideo:(id)sender;
 @end
 |  
                          5. 更新 ViewController.m 文件代码内容如下: 
                          
                            | #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad{
 [super viewDidLoad];
 }
 - (void)didReceiveMemoryWarning{
 [super didReceiveMemoryWarning];
 // Dispose of any resources that can be recreated.
 }
 -(IBAction)playAudio:(id)sender{
 NSString *path = [[NSBundle mainBundle]
 pathForResource:@"audioTest" ofType:@"mp3"];
 audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:
 [NSURL fileURLWithPath:path] error:NULL];
 [audioPlayer play];
 }
 -(IBAction)playVideo:(id)sender{
 NSString *path = [[NSBundle mainBundle]pathForResource:
 @"videoTest" ofType:@"mov"];
 moviePlayer = [[MPMoviePlayerViewController
 alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
 [self presentModalViewController:moviePlayer animated:NO];
 }
 @end
 |  
                          注意 
                          我们需要添加音频和视频文件,以确保我们得到预期的输出。 输出 
                          现在,当我们运行程序时,我们会得到下面的输出。 
 当我们点击播放视频时,我们会得到一个输出,如下图所示。 
 我们点击播放音频的时候,会听到声音。 | 
					|  |