Tuesday, 19 June 2012

Iphone Code for MEDIA (PLAYING AUDIO AND VIDEO)


MediaViewController.h

#import <UIKit/UIKit.h>

#import <MediaPlayer/MediaPlayer.h>

#import <AVFoundation/AVFoundation.h>

@interface MediaViewController : UIViewController {

            AVAudioPlayer *audioPlayer;

            IBOutlet UISlider *sliderVolume;

            IBOutlet UIProgressView *progressAudio;}

-(IBAction)playVideo;

-(IBAction)playAudio;

-(IBAction)pauseAudio;

-(IBAction)backPlay;

-(IBAction)forwardPlay;

-(IBAction)changeVolume;

@end

MediaViewController.m

#import "MediaViewController.h"

@implementation MediaViewController

-(IBAction)playVideo{


NSString *strVideoPath =  [[NSBundle mainBundle]pathForResource:@"rangam nemali kjannula" ofType:@"mp4"];

NSURL *url = [NSURL fileURLWithPath:strVideoPath];

MPMoviePlayerController *player = [[MPMoviePlayerController alloc]initWithContentURL:url];

self.view = player.view;

[player play];  }

-(IBAction)playAudio{         [audioPlayer play];  }

-(IBAction)pauseAudio{      [audioPlayer pause];}

-(IBAction)backPlay{

      audioPlayer.currentTime-=10;

            [audioPlayer play];  }

-(IBAction)forwardPlay{

         audioPlayer.currentTime+=10;

            [audioPlayer play];  }

-(IBAction)changeVolume{

       audioPlayer.volume  = sliderVolume.value;  }

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void)viewDidLoad {

    [super viewDidLoad];

NSString *strVideoPath =  [[NSBundle mainBundle]pathForResource:@"rangam nemali kjannula" ofType:@"mp4"];

            NSURL *url = [NSURL fileURLWithPath:strVideoPath];

            NSError *err;

            audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&err];

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateProgress) userInfo:nil repeats:YES]; }

-(void)updateProgress{

progressAudio.progress = audioPlayer.currentTime/audioPlayer.duration; }

0 comments:

Post a Comment