iPod Library Access Programming Guide 3 -- Media Item Picker

本文介绍如何使用iOS中的MediaItemPicker来让用户从iPod库中选择媒体项。文章详细解释了设置MediaItemPicker代理的方法,并提供了展示MediaItemPicker的示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Using the Media Item Picker

The media item picker is the pre-packaged view controller for letting a user choose media items from the device iPod library. Using the picker is very simple:

  1. Designate a controller object as a delegate of the picker.
  2. Invoke the picker from the controller.
  3. When the user indicates that they are finished, the delegate receives the chosen collection of media items and dismisses the picker.

Setting Up a Media Item Picker Delegate

@interface myController : UIViewController <MPMediaPickerControllerDelegate> {
    // interface declaration
}

Next, implement the two delegate methods from that protocol. The first method, shown in Listing 3-1, responds to the user having chosen some media items. It dismisses the picker and invokes the controller’s playback queue update method.

Listing 3-1  Responding to a new collection of media items from the picker
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker
            didPickMediaItems: (MPMediaItemCollection *) collection {
 
    [self dismissModalViewControllerAnimated: YES];
    [self updatePlayerQueueWithMediaCollection: collection];
}


Listing 3-2  Responding if the user cancels the picker
- (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker {
 
    [self dismissModalViewControllerAnimated: YES];
}

Displaying a Media Item Picker

Listing 3-3  Displaying a media item picker
MPMediaPickerController *picker =
    [[MPMediaPickerController alloc]
        initWithMediaTypes: MPMediaTypeAnyAudio];                   // 1
 
[picker setDelegate: self];                                         // 2
[picker setAllowsPickingMultipleItems: YES];                        // 3
picker.prompt =
    NSLocalizedString (@"Add songs to play",
                        "Prompt in media item picker");
 
[myController presentModalViewController: picker animated: YES];    // 4
[picker release];


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值