2012-06-13 71 views
0

傢伙遇到錯誤與結合UISlider到我的音樂應用程序,任何意見將是巨大的,這是我的第一個應用程序,我是一個新手...音頻在我的應用程序,播放暫停滑塊

該軌道運行良好,停止罰款,但當我嘗試跳過應用程序崩潰,我敢肯定,我已經錯過了一些東西,只需要一些新的眼睛上的代碼,希望有人可以建議...

NoGraceViewController.h

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

@interface NoGraceViewController : UIViewController<AVAudioPlayerDelegate> { 
    AVAudioPlayer *audioPlayer; 
    UISlider *volumeControl; 
} 

@property(nonatomic,retain)IBOutlet UISlider *volumeControl; 
@property(nonatomic,retain) AVAudioPlayer *audioPlayer; 
@property (weak, nonatomic) IBOutlet UITextField *timeLabel; 
@property (weak, nonatomic) IBOutlet UISlider *skipSlider; 

-(IBAction) nograceButton; 

-(IBAction)playbutton; 

-(IBAction)stopbutton; 

-(IBAction)skipSliderMoved; 

@end 

NoGraceViewController.m

#import "NoGraceViewController.h" 

@interface NoGraceViewController() 

@end 

@implementation NoGraceViewController 
@synthesize skipSlider; 
@synthesize timeLabel; 

-(IBAction) nograceButton { 
    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"http://itunes.apple.com/us/album/no-grace-original-mix-single/id392597812?uo=4"]]; 
} 

@synthesize audioPlayer; 

- (IBAction)playbutton 
{ 
    [audioPlayer play]; 

} 

-(IBAction)stopbutton 
{ 
    [audioPlayer stop]; 
} 

- (IBAction)skipSliderMoved:(UISlider *)sender { 
    self.audioPlayer.currentTime = self.audioPlayer.duration*sender.value; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    NSURL *url=[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"001.mp3" ofType:nil]]; 

    NSError *error; 
    audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error]; 
    if (error) 
    { 
     NSLog(@"Error in audioPlayer: %@", 
       [error localizedDescription]); 
    } else { 
     audioPlayer.delegate = self; 
     [audioPlayer prepareToPlay]; 
    } 

} 

- (void)viewDidUnload { 
    [self setSkipSlider:nil]; 
    [self setTimeLabel:nil]; 

    self.volumeControl=nil; 
    self.audioPlayer=nil; 
} 

-(void)updateDisplay { 
    self.skipSlider.value = self.audioPlayer.currentTime/self.audioPlayer.duration; 
    NSString *timeString = [[NSString alloc] initWithFormat:@"%d:%02d", (int) self.audioPlayer.currentTime/60,(int) self.audioPlayer.currentTime % 60]; 
    self.timeLabel.text = timeString; 
} 

@end 

回答

1

試試這個:

self.audioPlayer.currentTime = (self.audioPlayer.duration/100) * sender.value; 
相關問題