YouTip LogoYouTip

Ios Audio Video

iOS Audio and Video(Audio & Video)

iOS Audio and Video(Audio & Video)

--

iOS Tutorial

iOS Tutorial iOS Introduction iOS Environment Setup Objective C Basics Creating Your First iPhone Application iOS Actions and Outlets iOS Delegates iOS UI Elements iOS Accelerometer iOS Universal Applications iOS Camera Management iOS Location Operations iOS SQLite Database iOS Sending Email iOS Audio and Video(Audio & Video) iOS File Handling iOS Map Development iOS In-App Purchases iOS Integrating iAD iOS GameKit iOS Storyboards iOS Auto Layouts iOS Twitter and Facebook iOS Memory Management iOS Application Debugging iOS Sending Email iOS File Handling

Deep Dive

Development Tools

Smartphones

Mac OS

TV and Video Devices

Apple iOS

Programming

Computer Science

Media Players

MediaPlayer

Software

iOS Audio and Video(Audio & Video)


Introduction

Audio and video are quite common in the latest devices. Adding iosAVFoundation.framework and MediaPlayer.framework to your Xcode project will enable iOS support for audio and video (Audio & Video).

Example Steps

  1. Create a simple View-based application
  2. Select the project file, select the target, then add AVFoundation.framework and MediaPlayer.framework
  3. Add two buttons in ViewController.xib, create an action (action) for each to play audio and video respectively
  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;
    
}
-(IBAction)playAudio:(id)sender;
-(IBAction)playVideo:(id)sender;
@end
  1. Update ViewController.m as follows
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    ;
}

- (void)didReceiveMemoryWarning
{
   ;
   // Dispose of any resources that can be recreated.
}
-(IBAction)playAudio:(id)sender{
   NSString *path = [
   pathForResource:@"audioTest" ofType:@"mp3"];
   audioPlayer = [initWithContentsOfURL:
   [NSURL fileURLWithPath:path] error:NULL];
   ;
}
-(IBAction)playVideo:(id)sender{
   NSString *path = [pathForResource:
   @"videoTest" ofType:@"mov"];
   moviePlayer = [initWithContentURL:[NSURL fi
← Ios FileIos Sending Email β†’