Saturday, 13 April 2013

#P5 Music Player Application


Description
Develop Sitar music player application which can run on iOS platform. The application will run sitar music when user click on the sitar image.
Screens

Project Creation
  • Create new Xcode project and select “Single View project” template under iOS->Application
  • Add AVFoundation Framework
  • Open ViewController.xib file by double clicking it and add button and set its method name and image

Do method implementation
ViewController.h


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

@interface ViewController : UIViewController <AVAudioPlayerDelegate> {
    AVAudioPlayer *player;
}

@property (nonatomic, retain) AVAudioPlayer *player;

-(IBAction)playToggele;

@end

ViewController.m


#import "ViewController.h"

@interface ViewController ()

@end

Boolean playing = NO;

@implementation ViewController

@synthesize player;

-(void)playToggele{
   
    if (playing==NO) {
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
       
        NSBundle *bundle = [NSBundle mainBundle];
        NSString *path = [bundle pathForResource:@"sitar" ofType:@"mp3"];
       
        NSURL *url = [NSURL fileURLWithPath:path];
       
        player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
        [player prepareToPlay];
       
        player.delegate=self;
        [player play];
       
        playing=YES;
    } else if(playing==YES){
        [player pause];
       
        playing=NO;
    }
}

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

- (void)dealloc {
    [player release];
    [super dealloc];
    }

@end

No comments:

Post a Comment