做一个音乐播放器应用程序!上一首和下一首曲目

发布于 2024-12-09 18:33:45 字数 746 浏览 2 评论 0原文

如何在不使用 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];        
}

How can I make a app to iphone without using ipod library, and doing the next song and the previous song??

I think the best way is doing an array with the songs, but I don't know how to do. Someone can helps me??

My app is working, with pause, play, current time and volume slider... but this part of next song I really don't know!

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2024-12-16 18:33:45
    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];
    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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文