Audio And Video

How To Manage Audio And Video File

Steps Involved

Step 1. Create a simple View based application.

Step 2. Select your project file, select targets, and then we should addAVFoundation.framework and MediaPlayer.framework.

Step 3. Add two buttons in ViewController.xib and create an action for playing audio and video respectively.

Step 4. Update ViewController.h as follows −

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController : UIViewController
AVAudioPlayer *audioPlayer;
MPMoviePlayerViewController *moviePlayer;


Step 5. Update ViewController.m as follows −

#import "ViewController.h"
@interface ViewController ()
@implementation ViewController
- (void)viewDidLoad
[super viewDidLoad];
- (void)didReceiveMemoryWarning
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
NSString *path = [[NSBundle mainBundle]
pathForResource:@"audioTest" ofType:@"mp3"];
audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:
[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer play];
NSString *path = [[NSBundle mainBundle]pathForResource:
@"videoTest" ofType:@"mov"];
moviePlayer = [[MPMoviePlayerViewController
alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
[self presentModalViewController:moviePlayer animated:NO];
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.