ios - 做一个音乐播放器应用程序!上一轨道和下一轨道

标签 ios objective-c audio avaudioplayer playback

如何在不使用 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/

相关文章:

ios - 使用 Office-365-SDK-for-iOS

ios - 如何在txt文件中编写iOS 7

objective-c - 通过 CocoaPods 在 github 上使用 Restkit 的分支?

ios - 从ios中的UITabBarController中删除标签栏的安全方法

ios - 使用 AVAudioSession AVAudioSessionCategoryPlayAndRecord 静音所有推送通知声音和振动。即使应用程序在后台

java - 如何将音频流转换为 .wav 文件并保存

ios - 什么时候不为 objective-c 中的委托(delegate)使用协议(protocol)?

ios - 如何在 iOS 中设置表格 View 单元格属性的初始值

ios - ScrollView 上不需要的 subview 反弹

javascript - 对网络上麦克风的影响