MPMediaItems 原始歌曲数据
我想知道如何访问 MPMediaItem 的原始数据。
有什么想法吗?
I was wondering how to access an MPMediaItem's raw data.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想知道如何访问 MPMediaItem 的原始数据。
有什么想法吗?
I was wondering how to access an MPMediaItem's raw data.
Any ideas?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
您可以通过以下方式获取媒体项的数据:
此代码仅适用于 ios 4.0 及更高版本
祝您好运!
you can obtain the media item's data in such way:
This code will work only on ios 4.0 and later
Good luck!
当然,您可以访问
MPMediaItem
的数据。虽然不是一下子就很清楚,但它确实有效。操作方法如下:MPMediaItemPropertyAssetURL
属性获取媒体项的 URL 使用AVURLAsset
使用此AVAssetReader
您想要从
AVURLAsset
读取的 AVAssetTrackAVAssetReaderTrackOutput
AVAssetReader
和-startReading
AVAssetReaderTrackOutput
的-copyNextSampleBuffer
获取所有数据,这是我的一个项目中的一些示例代码(这不是我的代码宝石,是在我的编码黑暗时代写的):
Of course you can access the data of a
MPMediaItem
. It's not crystal clear at once but it works. Here's how:MPMediaItemPropertyAssetURL
propertyAVURLAsset
with this URLAVAssetReader
with this assetAVAssetTrack
you want to read from theAVURLAsset
AVAssetReaderTrackOutput
with this trackAVAssetReader
created before and-startReading
AVAssetReaderTrackOutput
's-copyNextSampleBuffer
Here is some sample code from a project of mine (this is not a code jewel of mine, wrote it some time back in my coding dark ages):
你不能,而且没有解决方法。 MPMediaItem 不是实际的媒体片段,它只是有关通过 RPC 从另一个进程传递到应用程序的媒体项目的元数据。在您的地址空间中无法访问该项目本身的数据。
我应该注意,即使您有 MPMediaItem,它的数据也可能不会加载到设备内存中。 iPhone 上的闪存速度很慢,内存也很稀缺。虽然 Apple 可能不希望您访问支持 MPMediaItem 的原始数据,但他们很可能不会费心处理它,因为他们不想投入必要的时间来处理 API。如果他们确实提供了对这样的东西的访问,那么它几乎肯定不会作为 NSData,但更有可能作为 NSURL,他们会给你的应用程序允许它打开文件并流式传输数据。
无论如何,如果您想要该功能,您应该提交一份要求的错误报告。
另外,请注意,请勿在发送给 Apple 的错误报告中提及您的年龄。我认为你为手机编写应用程序非常酷,当我在你这个年纪时,我喜欢尝试计算机(当时我正在研究用 Lisp 编写的东西)。问题是你不能在美国合法地同意合同,这就是开发者协议明确禁止你加入的原因。 协议第一段:
如果您向 WWDR 代表提及您未达到法定成年年龄,他们可能会意识到您违反了协议,并有义务终止您的开发者帐户。只是一个友好的警告。
You can't, and there are no workaround. An MPMediaItem is not the actual piece of media, it is just the metadata about the media item communicated to the application via RPC from another process. The data for the item itself is not accessible in your address space.
I should note that even if you have the MPMediaItem its data probably is not loaded into the devices memory. The flash on the iPhone is slow and memory is scarce. While Apple may not want you to have access to the raw data backing an MPMediaItem, it is just as likely that they didn't bother dealing with it because they didn't want to invest the time necessary to deal with the APIs. If they did provide access to such a thing it almost certainly would not be as an NSData, but more likely as an NSURL they would give your application that would allow it to open the file and stream through the data.
In any event, if you want the functionality, you should file a bug report asking for.
Also, as a side note, don't mention your age in a bug report you send to Apple. I think it is very cool you are writing apps for the phone, when I was your age I loved experimenting with computers (back then I was working on things written in Lisp). The thing is you cannot legally agree to a contract in the United States, which is why the developer agreement specifically prohibits you from joining. From the first paragraph of the agreement:
If you mention to a WWDR representative that you are not of age of majority they may realize you are in violation of the agreement and be obligated to terminate your developer account. Just a friendly warning.