一.播放音频
NSURL *url = [NSURL URLWithString:voiceintro];
NSData * audioData = [NSData dataWithContentsOfURL:url];
//将数据保存到本地指定位置
NSString *docDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.mp3", docDirPath , @"temp"];
[audioData writeToFile:filePath atomically:YES];
//播放本地音乐
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:nil];
//预播放
[avAudioPlayer prepareToPlay];
[voicebtn setTitleColor:MainColor forState:UIControlStateNormal];
[voicebtn addTarget:self action:@selector(startvoice) forControlEvents:UIControlEventTouchUpInside];
//点击播放按钮
-(void)startvoice
{
[avAudioPlayer play];
}
二.TggStarEvaluationView 星星评价视图
TggStarEvaluationView 星星评价视图
网友评论