Saturday, 21 February 2015

Audio & Video Player



Audio & Video Player


1 ) First Add Two Frameworks :

- AVFoundation.Framework
- MediaPlayer.Framework

2 ) Add Two Button in Storyboard :

3 ) Write This Code In ViewController.h :

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController

{
    AVAudioPlayer *audioplayer;
    MPMoviePlayerViewController *movieplayer;
}

- (IBAction)audioplay:(id)sender;

- (IBAction)videoplay:(id)sender;


@end

4 ) Write This Code In ViewController.m :

@implementation ViewController



- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)audioplay:(id)sender
{
    
    NSString *path = [[NSBundle mainBundle]pathForResource:
                      @"Saturday_Saturday_(Humpty_Sharma_Ki_Dulhania(wapking.cc)" ofType:@"mp3"];
    movieplayer = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:path]];
    [self presentModalViewController:movieplayer animated:NO];
  //  [audioplayer play];
    

    
}

- (IBAction)videoplay:(id)sender
{
    
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"Movie" ofType:@"mp4" inDirectory:nil]];
    movieplayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    
    [self presentMoviePlayerViewControllerAnimated:movieplayer];
    
    
    
//    NSString *path = [[NSBundle mainBundle] pathForResource:@"Movie" ofType:@"mp4"inDirectory:nil];
//    
// NSURL *movieURL = [NSURL fileURLWithPath:path];
//    
// movieplayer= [[ MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
//    
// [self presentMoviePlayerViewControllerAnimated:movieplayer];
    


}

@end

No comments:

Post a Comment