我正在尝试使用 MPMusicPlayerController 通过空中播放在电视上播放音乐。如何检查其他输入是否正在使用播放?
问问题
1825 次
3 回答
1
几个可能有用的现有帖子:
是否有在 Objective-C 中检测 AirPlay 的通知?
如何在 Airplay 处于活动状态时自定义 Airplay 按钮
第二个链接中有一篇文章定义了- (BOOL)isAirPlayActive
巧妙地使用 AudioSession 框架来确定当前音频输出路径的方法。
于 2013-06-21T09:31:52.283 回答
0
这是另一种检测airplay是否处于活动状态的解决方案
- (BOOL)isAirPlayActive
{
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;
AVAudioSessionPortDescription* output = [currentRoute.outputs firstObject];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
return [output.portType isEqualToString:AVAudioSessionPortAirPlay];
}
于 2015-08-05T03:27:30.247 回答
0
我也遇到了这个问题,最后我使用 arp -n 来获取 airplay 设备的 mac 地址,然后使用 tcpdump 来嗅探到它的流量:
ipaddress=$(ping -c 1 $tvhostname | awk -F'[()]' '/PING/{print $2}')
arp -n $ipaddress &> /var/tmp/arp-output
fieldindex='$4'
# Parse something of the form ? (10.37.109.150) at 40:33:1a:3d:e6:ee on en0 ifscope [ethernet]
# The awk quotes get a bit messy with the variable substitution, so split the expression up
echo Parsing mac address from line `awk -F"[ ]" "/\($ipaddress\)/{print}" /var/tmp/arp-output`
macaddress=`awk -F"[ ]" "/($ipaddress)/{print $fieldindex}" /var/tmp/arp-output`
sudo tcpdump -i $wifidevice -I ether dst $macaddress &> /var/tmp/airplay-tcpdump-output
# Get the PID of the tcpdump command
pid=$!
# Capture 10 seconds of output, then kill the job
sleep 10
sudo kill $pid
# Process the output file to see how many packets are reported captured
packetcount=`awk -F'[ ]' '/captured/{print $1}' /var/tmp/airplay-tcpdump-output`
echo Finished sniffing packets - there were $packetcount.
完整的脚本最终有点涉及,所以我把它写在博客文章中。
于 2016-01-08T17:12:22.627 回答