Iphone:如何在应用程序内显示库中的歌曲列表 [英] Iphone: How to show list of songs from library inside application

查看:90
本文介绍了Iphone:如何在应用程序内显示库中的歌曲列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用程序内的列表中显示用户ipod中所有歌曲的列表。当用户点击一首歌时,我想存储这首歌的名字。

I want to show the list of all songs from the user's ipod in a list inside my application. When the user clicks a song I want to store the name of the this song.

我后来想要抓住那首歌的名字并播放它(但不是正确的)离开)。

I also later want to grab the name of that song and play it (but not right away).

任何想法从哪里开始?我知道它可能在Media.Player框架中的某处,但我似乎无法弄清楚如何从应用程序内部实际查看歌曲列表

Any ideas where to start for this? I know it is probably somewhere in the Media.Player framework but I can't seem to figure out how to actual view the list of songs from inside the application

推荐答案

您可以使用以下方法调用MPMediaPickerController:

You can call up the MPMediaPickerController using this:

- (IBAction) selectSong: (id) sender 
{   
    MPMediaPickerController *picker =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

    picker.delegate                     = self;
    picker.allowsPickingMultipleItems   = NO;
    picker.prompt                       = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");

    [self presentModalViewController: picker animated: YES];
}

然后您可以使用类似的内容将选定的歌曲添加到您自己的阵列中这个。

Then you can add the songs that were selected to your own array using something like this.

注意:您将使用 valueForProperty 。

- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection 
{
    [self dismissModalViewControllerAnimated: YES];
    someMutableArray = [mediaItemCollection mutableCopy];
}

然后这是一种自我解释但必要的:

Then this is kind of self explanatory but necessary:

- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker 
{   
    [self dismissModalViewControllerAnimated: YES]; 
}

有关更多信息,请访问 Apple的iPod库访问编程指南

For more information visit Apple's iPod Library Access Programming Guide

这篇关于Iphone:如何在应用程序内显示库中的歌曲列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆