使用 MPMediaPicker 选择作为 AVAudioPlayer 输入

发布于 2024-11-24 16:27:48 字数 191 浏览 3 评论 0原文

我正在为听力障碍者编写一个应用程序。我希望从 iTunes 库中获取曲目,并在我的应用程序中有一个用于平移的滑块。我不想使用 OpenAL(这不是游戏 - 我再说一遍,这是一个媒体播放器)。那么,由于 AVAudioPlayer 具有简单的平移方法,我可以从 MPMediaPicker 中进行选择并将它们输入到 AVAudioPlayer 中,以便我可以平移它们吗?

I'm programming an application for the hearing-impaired. I'm hoping to take tracks from the iTunes library, and in my app have a slider for panning. I don't want to use OpenAL (this isn't a game - I repeat this is a media player). So since AVAudioPlayer has the easy pan method, can I take selections from the MPMediaPicker and feed them into the AVAudioPlayer so I can pan them?

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

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

发布评论

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

评论(2

怼怹恏 2024-12-01 16:27:48

我没有做很多 iOS 开发,但我相信有两种方法。

方法#1
您需要将 /System/Library/Frameworks/AVFoundation.framework 添加到 Xcode 中的目标并 #import AVAudioPlayer.h 以及您需要将 MediaPlayer.framework 添加到 Xcode 中的目标并 #import 。

对于此操作,您需要 MPMediaPicker 将歌曲数据传递给 AVAMedia Player。可以这样完成:(

@interface MusicPlayerDemoViewController : UIViewController <MPMediaPickerControllerDelegate> {
...
}
...
// This action should open the media picker
- (IBAction)openMediaPicker:(id)sender;
@end

// MusicPlayerDemoViewController.m
- (IBAction)openMediaPicker:(id)sender {
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = NO; // this is the default   
    [self presentModalViewController:mediaPicker animated:YES];
    [mediaPicker release];
}                                   

// Media picker delegate methods
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
  // We need to dismiss the picker
  [self dismissModalViewControllerAnimated:YES];

代码继续如下,空白处供您填写)

此时,调用 AVAAUDIOPLAYER 类并告诉它播放 mediaItemCollection 。请记住在播放前停止音频,因为它会同时播放多首歌曲。

}

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
    // User did not select anything
    // We need to dismiss the picker
    [self dismissModalViewControllerAnimated:YES];
}

现在,一旦完成,用户需要选择一首新歌曲。您可以围绕整个事情创建一个 WHILE 循环,其中条件是当前时间 >= 持续时间(来自 AVAAUDIO 播放器),

或者,您可以创建一个按钮来打开选择器

有关更多问题,请查看:

http://oleb.net/blog/ 2009/07/the-music-player-framework-in-the-iphone-sdk/(我使用了他们的大部分代码)

http://developer.apple.com/library/ ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

祝你好运!

德里克

I dont do a lot of iOS development, but I believe there are two ways.

Method #1
You need to add /System/Library/Frameworks/AVFoundation.framework to your target in Xcode and #import AVAudioPlayer.h as well as You need to add MediaPlayer.framework to your target in Xcode and #import .

For this operation, you need MPMediaPicker to pass the song data to AVAMedia Player. That can be accomplished like this:

@interface MusicPlayerDemoViewController : UIViewController <MPMediaPickerControllerDelegate> {
...
}
...
// This action should open the media picker
- (IBAction)openMediaPicker:(id)sender;
@end

// MusicPlayerDemoViewController.m
- (IBAction)openMediaPicker:(id)sender {
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeMusic];
    mediaPicker.delegate = self;
    mediaPicker.allowsPickingMultipleItems = NO; // this is the default   
    [self presentModalViewController:mediaPicker animated:YES];
    [mediaPicker release];
}                                   

// Media picker delegate methods
- (void)mediaPicker: (MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
  // We need to dismiss the picker
  [self dismissModalViewControllerAnimated:YES];

(Code Continues Below, the blanks are for you to fill in)

AT THIS POINT, CALL THE AVAAUDIOPLAYER CLASS AND TELL IT TO PLAY mediaItemCollection . REMEMBER TO STOP AUDIO BEFORE PLAYING, AS IT WILL PLAY MULTIPLE SONGS AT ONCE.

}

- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
    // User did not select anything
    // We need to dismiss the picker
    [self dismissModalViewControllerAnimated:YES];
}

NOW, ONCE THIS IS DONE THE USER NEEDS TO SELECT A NEW SONG. YOU COULD EITHER CREATE A WHILE LOOP AROUND THE WHOLE THING, WHERE THE CONDITIONAL IS CURRENT TIME >= DURATION (FROM AVAAUDIO PLAYER),

ALTERNATIVELY, YOU COULD CREATE A BUTTON TO OPEN THE PICKER

For more questions checkout:

http://oleb.net/blog/2009/07/the-music-player-framework-in-the-iphone-sdk/ (I used much of their code)

http://developer.apple.com/library/ios/#DOCUMENTATION/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

Good Luck!

Derek

最美的太阳 2024-12-01 16:27:48
  1. 尝试让 AVAMediaPlayer 播放变量 mediaItemCollection。这是由选择器通过上面的代码指定为歌曲位置的。如果这不起作用,请确保 AVAMediaPlayer 使用与 MpMediaPicker 相同的输入变量类型(格式,如 ID 或文件夹位置)。

  2. 该错误消息听起来像是一个技术问题。我唯一能想到的是 AVAudio 播放器或 MPmedia 播放器正在寻找 Volume 变量(它是必需的?),但找不到。我无法真正回答这个问题,因为我不进行 iPhone 开发,请尝试在论坛或网站上寻求帮助。

听起来你做得很好!如果你有兴趣的话,(我不知道你是否住在DA)Cochran先生(高中部的学生主任)正在教授iPhone开发班和AP计算机科学班(我在)。如果你想更进一步,或者你想问问题,我知道他也非常高兴!

祝你好运!完成后请告诉我,以便我测试结果!

  1. Try having AVAMediaPlayer play the variable mediaItemCollection. This was assigned by the picker to be the song location by the code above. If this does not work make sure that AVAMediaPlayer uses the same input variable type (format, like an ID or a folder location) as MpMediaPicker.

  2. That error message sounds like a technical issue. The only thing I can think of is that AVAAudio player or MPmedia player is looking for a Volume variable (it is required?) and can't find one. I can't really answer this one as I don't do iPhone Development, try there forums or website for some help.

Sounds like you are doing a good job! If you are interested, (I don't know if you are staying at DA) Mr. Cochran (the dean of students at the Upper School) is teaching a iPhone Development Class and a AP Computer Science Class (I am in). If you want to take it further, or you want to just ask questions I know he is more than happy too!

Good Luck! Tell me when it is finished so I can test the results!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文