如何获取另一个应用程序当前正在播放的音频 [英] How to get another app's currently playing audio

查看:514
本文介绍了如何获取另一个应用程序当前正在播放的音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问另一个应用程序当前正在播放的音频-实际的音频项目,但也欢迎使用元数据.我可以看到,这个问题已经问了很多,但多年来却很少提供解决方案.我了解Apple的可能理念,不希望某个应用程序能够做到这一点.我还了解到,这样的请求可能是可能在iOS API之外.话虽这么说,我真的很想要某种解决方案.

从逻辑上讲,我认为

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo 

应返回当前正在播放的内容的信息;但是,正如其他人提到的那样,对于在应用程序外部播放的音频,此值始终为nil.值得注意的是,流行的音频应用似乎无法使用MPNowPlayingInfoCenter类,从而使此类音频无法显示.

如果使用默认的音乐应用,则可以使用

MPMusicPlayerController.systemMusicPlayer().nowPlayingItem

但是,通过播客应用程序,Spotify,Pandora,Safari等访问音频播放的更一致的方法是什么?

有人找到解决方案吗?是否有任何支持此功能的旧Objective-C框架?

如果有某种方法可以访问当前正在播放的项目的音频路径,则一种方法可能是可行的.例如,如果我可以获取当前播放项目的路径,则可以从中创建一个AV对象:

AVAudioPlayer(contentsOfURL: audioUrl)

那么有什么方法可以获取当前播放项目的音频URL并以此方式使用它吗?

另一种方法更好吗?

如果不存在本机解决方案 ,是否有可能将 bodge 结合在一起使之起作用?欢迎任何意见或想法.

我不相信任何人都能够实现这一目标.但是,我想很多人都想这么做.如果已解决,请链接! :)

解决方案

当前在iOS中无法实现.只需将AVAudioSession类别选项更改为.MixWithOthers,这将是从其他应用程序获取信息歌曲信息的选项,则会使您的nowPlayingInfo被忽略.

iOS仅考虑将非混合应用程序包含在MPNowPlayingInfoCenter中,因为如果同时播放多个混合应用程序,则不确定哪个应用程序会显示在(例如)控制中心中.

建议:一种选择是使用音乐指纹算法通过在您的App中记录正在播放的内容来识别正在播放的内容.

一些朝着这个方向发展的有趣项目:

Gracenote https://developer.gracenote.com/ Gracenote(其中归索尼所有)已开放其SDK和API,并拥有适当的开发者门户.

EchoNest& Spotify API http://developer.echonest.com/自2016年3月起与Spotify融合

ACRCloud https://www.acrcloud.com/提供ACR解决方案用于自定义文件,例如电视广告,音乐tec

How can I access another app's currently playing audio - the actual audio item but metadata is welcome too. I can see that this question has been asked a lot but with few solutions being offered over the years. I understand apple's philosophy for probably not wanting an app to be able to do this. I also understand that such a request is probably outside of the iOS API. With that being said, I would really like some kind of solution.

Logically, I feel that

MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo 

should return the info for whatever is currently playing; however, as others have mentioned, this value is always nil for audio being played outside of your app. Notably, popular audio apps seem to fail to use the MPNowPlayingInfoCenter class, making such audio fail to appear.

If using the default music app, one can use

MPMusicPlayerController.systemMusicPlayer().nowPlayingItem

However, what is a more consistent way to access audio playing through the podcasts app, Spotify, Pandora, Safari, etc?

Has anyone found a solution to this? Are there any old Objective-C frameworks that support this functionality?

One approach might be viable if there is there some way I can access the audio path of the item currently being played. For example, if I could get the path of the currently playing item, I could create an AV object from it:

AVAudioPlayer(contentsOfURL: audioUrl)

So is there a way I can get the audio url of the currently playing item and use it that way?

Is another approach better?

If a native solution does not exist, is it possible to bodge something together for it to work? Any advice or ideas welcome.

Edit: I don't believe anybody has been able to achieve this; however, I think a lot of people would like to. If this has been addressed, please link it! :)

解决方案

This isn't currently possible in iOS. Just changing your AVAudioSession category options to .MixWithOthers, what will be an option to get info Song Info from other apps, causes your nowPlayingInfo to be ignored.

iOS only considers non-mixing apps for inclusion in MPNowPlayingInfoCenter, because there is uncertainty as to which app would show up in (e.g.) Control Center if there are multiple mixing apps playing at the same time.

Proposal: An option would be to use a music fingerprinting algorithm to recognize what is being played by recording it from your App.

Some interesting projects in this direction:

Gracenote https://developer.gracenote.com/ Gracenote (which is owned by Sony) has opened up it's SDKs and APIs and has a proper dev portal.

EchoNest & Spotify API http://developer.echonest.com/ Fusioned with Spotify since March 2016

ACRCloud https://www.acrcloud.com/ offers ACR solutions for custom files such as TV commercials, music tec

这篇关于如何获取另一个应用程序当前正在播放的音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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