gpt4 book ai didi

iphone - 我的应用程序中的音频,播放暂停 slider

转载 作者:行者123 更新时间:2023-11-29 04:36:21 24 4
gpt4 key购买 nike

伙计们,我在将 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

最佳答案

试试这个:

self.audioPlayer.currentTime = (self.audioPlayer.duration / 100) * sender.value;

关于iphone - 我的应用程序中的音频,播放暂停 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11021247/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com