如何在不使用 ipod 库、做下一首和上一首的情况下为 iphone 制作应用程序?
我认为最好的方法是对歌曲进行数组处理,但我不知道该怎么做。有人可以帮助我吗??
我的应用程序运行正常,带有暂停、播放、当前时间和音量 slider ...但是下一首歌曲的这一部分我真的不知道!
- (void)viewDidLoad {
//initialize string to the path of the song in the resource folder
NSString *myMusic = [[NSBundle mainBundle]pathForResource:@"gastando" ofType:@"mp3"];
player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:myMusic] error:NULL];
player.numberOfLoops = 0;
player.volume = slider.value;
timeSlider.maximumValue = player.duration;
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timeLoader) userInfo:nil repeats:YES];
[super viewDidLoad];
}
最佳答案
MPMusicPlayerController *musicPlayer = [MPMusicPlayerController iPodMusicPlayer];
//get all media
MPMediaQuery *everything = [[MPMediaQuery alloc] init];
//empty song list
NSMutableArray *songList = [[NSMutableArray alloc] init ];
for (int i = 0 ; i < [[everything items] count] ; i++){
MPMediaItem *media = (MPMediaItem*)[[everything items] objectAtIndex:i];
NSInteger mediaType = [[media valueForProperty:MPMediaItemPropertyMediaType] intValue];
//only want audio
if (mediaType <= MPMediaTypeAnyAudio) {
[songList addObject:media];
}
}
//create music collection out of it
MPMediaItemCollection *musicCollection = [MPMediaItemCollection collectionWithItems:songList];
//set the playlist
[musicPlayer setQueueWithItemCollection:musicCollection];
[everything release];
[songList release];
关于ios - 做一个音乐播放器应用程序!上一轨道和下一轨道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7769936/