bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

iOS Audio and Video

 

The AV Foundation framework on the iOS SDK permits developers to play and record audio and video with simplicity. In addition the Media Player framework permits developers to play audio and video files.

Before executing the code you have to insert the AVFoundation.framework and MediaPlayer.framework frameworks to Xcode project. This can be achieved using following steps:

Step 1 – Find your target in Xcode project.

Step 2 – Right click on the target and select Add→Existing Frameworks.

Step 3 – Restrain the Command key and select AVFoundation.framework and MediaPlayer.framework from the list.

Step 4 – Choose Add.

Step 5 – Insert 2 buttons in ViewController.xib and make an action for playing audio and video in that order.

Step 6 – Change ViewController.h as follows –

#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

 

Step 7 – Change ViewController.m as follows:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(void)viewDidLoad

{

[super viewDidLoad];

}

-(void)didReceiveMemoryWarning
{

[super didReceiveMemoryWarning];

}

-(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

"0 Responses on iOS Audio and Video"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free iOS Audio and Video.