IOS学习:AVAudioPlayer播放音乐文件及读取ipod库中的音乐文件(3)
来源:未知 责任编辑:责任编辑 发表时间:2015-03-01 01:30 点击:次
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateSlider) userInfo:nil repeats:YES];
// 从ipod库中读出音乐文件
// MPMediaQuery *everything = [[MPMediaQuery alloc] init];
// // 读取条件
// MPMediaPropertyPredicate *albumNamePredicate =
// [MPMediaPropertyPredicate predicateWithValue:[NSNumber numberWithInt:MPMediaTypeMusic ] forProperty: MPMediaItemPropertyMediaType];
// [everything addFilterPredicate:albumNamePredicate];
//
// NSLog(@"Logging items from a generic query...");
// NSArray *itemsFromGenericQuery = [everything items];
// for (MPMediaItem *song in itemsFromGenericQuery) {
// NSString *songTitle = [song valueForProperty: MPMediaItemPropertyTitle];
// NSLog (@"%@", songTitle);
// }
//
// [everything release];
}
// 更新播放进度
- (void)updateSlider {
slider.value = player.currentTime;
}
// 进度滑块变化时,跳转到进度播放
- (void)sliderValueChange:(UISlider *)mSlider {
player.currentTime = mSlider.value;
NSLog(@"value: %.0f", mSlider.value);
}
// 停止
- (void)stop {
player.currentTime = 0;
[player stop];
}
// 暂停
- (void)pause {
[player pause];
NSLog(@"pause");
}
// 开始播放
- (void)playMusic {
NSLog(@"start play");
[player play];
}
#pragma mark - AVAudioPlayerDelegate
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag {
// 播放完成时调用 只有当播放结束时才会调用,循环播放时不会调
[timer invalidate];
NSLog(@"audioPlayerDidFinishPlaying");
}
/* if an error occurs while decoding it will be reported to the delegate. */
- (void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error {
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>