2013-06-04 67 views

回答

0

這裏是另一種解決方案,以檢測是否單曲是活動

- (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]; 
} 
0

我有這個問題爲好,我結束了使用ARP -n以獲取點播設備的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. 

完整的劇本最終是有點麻煩,所以我在寫blog post它。

相關問題