如何在不使用ipod库,不播放下一首歌和上一首歌的情况下将应用制作到iPhone?

我认为最好的方法是对歌曲进行排列,但是我不知道该怎么做。有人可以帮助我吗?

我的应用程序正在运行,具有暂停,播放,当前时间和音量滑块...但是我真的不知道下一首歌的这一部分!

- (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];

09-27 06:21