Skip to content

Commit

Permalink
airplay compatibility boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
jcm93 committed Jul 17, 2017
1 parent 2679005 commit c135617
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 185 deletions.
4 changes: 4 additions & 0 deletions jmc.xcodeproj/project.pbxproj
Expand Up @@ -121,6 +121,7 @@
0DC7127C1E2F115A0054ECE6 /* ImportErrorWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DC7127A1E2F115A0054ECE6 /* ImportErrorWindowController.swift */; };
0DC7127D1E2F115A0054ECE6 /* ImportErrorWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0DC7127B1E2F115A0054ECE6 /* ImportErrorWindowController.xib */; };
0DCF1D1C1F1D113600240202 /* Sparkle.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0DCF1D191F1D10DC00240202 /* Sparkle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
0DCF1D251F1D3C6300240202 /* AirPlayDeviceHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0DCF1D241F1D3C6300240202 /* AirPlayDeviceHandler.swift */; };
0DD0DAE61E53A8EE00807CAC /* flac.rb in Resources */ = {isa = PBXBuildFile; fileRef = 0DD0DAA31E53A8EE00807CAC /* flac.rb */; };
0DD0DAE71E53A8EE00807CAC /* AUTHORS in Resources */ = {isa = PBXBuildFile; fileRef = 0DD0DAA41E53A8EE00807CAC /* AUTHORS */; };
0DD0DAE81E53A8EE00807CAC /* flac in Resources */ = {isa = PBXBuildFile; fileRef = 0DD0DAA61E53A8EE00807CAC /* flac */; };
Expand Down Expand Up @@ -352,6 +353,7 @@
0DC7127A1E2F115A0054ECE6 /* ImportErrorWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImportErrorWindowController.swift; path = "Other Windows/ImportErrorWindowController.swift"; sourceTree = "<group>"; };
0DC7127B1E2F115A0054ECE6 /* ImportErrorWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ImportErrorWindowController.xib; path = "Other Windows/ImportErrorWindowController.xib"; sourceTree = "<group>"; };
0DCF1D191F1D10DC00240202 /* Sparkle.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Sparkle.framework; path = "../../Downloads/Sparkle-1.18.0/Sparkle.framework"; sourceTree = "<group>"; };
0DCF1D241F1D3C6300240202 /* AirPlayDeviceHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AirPlayDeviceHandler.swift; sourceTree = "<group>"; };
0DD0DAA31E53A8EE00807CAC /* flac.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = flac.rb; sourceTree = "<group>"; };
0DD0DAA41E53A8EE00807CAC /* AUTHORS */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS; sourceTree = "<group>"; };
0DD0DAA61E53A8EE00807CAC /* flac */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = flac; sourceTree = "<group>"; };
Expand Down Expand Up @@ -631,6 +633,7 @@
children = (
0DD0DB0D1E54425800807CAC /* FlacDecoder.swift */,
0D1BDFA41D0F44A70092FBA0 /* AudioModule.swift */,
0DCF1D241F1D3C6300240202 /* AirPlayDeviceHandler.swift */,
0D606EF51E7B4C21007AE152 /* FileBufferer.swift */,
0D606EF81E7B4DB0007AE152 /* AVAudioFileBufferer.swift */,
);
Expand Down Expand Up @@ -1299,6 +1302,7 @@
0DE486831EA579FD009B226B /* AddWatchFolderSheetController.swift in Sources */,
0D76F69B1D24622F00C6E70F /* TagEditorWindow.swift in Sources */,
0D1BDFA51D0F44A70092FBA0 /* AudioModule.swift in Sources */,
0DCF1D251F1D3C6300240202 /* AirPlayDeviceHandler.swift in Sources */,
0DE957D81EEC5465008CBECF /* OrganizationTemplateBundle+CoreDataProperties.swift in Sources */,
0D8AFE581E6D136D004AC584 /* MediaScannerSheet.swift in Sources */,
0D592A4D1EDF6C8B0054D553 /* TrackView+CoreDataClass.swift in Sources */,
Expand Down
Binary file not shown.
Expand Up @@ -84,11 +84,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "jmc/Delegate:Main Window Controller/MainWindowController.swift"
timestampString = "521667626.788035"
timestampString = "522006893.470967"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "328"
endingLineNumber = "328"
startingLineNumber = "332"
endingLineNumber = "332"
landmarkName = "tempBreak(_:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
71 changes: 71 additions & 0 deletions jmc/AirPlayDeviceHandler.swift
@@ -0,0 +1,71 @@
//
// AirPlayDeviceHandler.swift
// jmc
//
// Created by John Moody on 7/17/17.
// Copyright © 2017 John Moody. All rights reserved.
//

import Cocoa
import CoreAudio
import CoreFoundation

class AirPlayDestination: NSObject {

var name: String
var id: UInt32

init(id: UInt32, airPlayDevice: UInt32) {
self.id = id
var sourceID: UInt32 = 0
var nameAddr = AudioObjectPropertyAddress(mSelector: kAudioDevicePropertyDataSourceNameForIDCFString, mScope: kAudioObjectPropertyScopeOutput, mElement: kAudioObjectPropertyElementMaster)
var value: CFString = "" as CFString
var audioValueTranslation = AudioValueTranslation(mInputData: &sourceID, mInputDataSize: UInt32(MemoryLayout<UInt32>.size), mOutputData: &value, mOutputDataSize: UInt32(MemoryLayout<CFString>.size))
var propsize = UInt32(MemoryLayout<AudioValueTranslation>.size)
AudioObjectGetPropertyData(airPlayDevice, &nameAddr, 0, nil, &propsize, &audioValueTranslation)
self.name = value as String
}

}

class AirPlayDeviceHandler: NSObject {

var outputs = [AirPlayDestination]()
var device: UInt32 = 0


override init() {
var addr = AudioObjectPropertyAddress(mSelector: kAudioHardwarePropertyDevices, mScope: kAudioObjectPropertyScopeWildcard, mElement: kAudioObjectPropertyElementWildcard)
var propsize: UInt32 = 0
AudioObjectGetPropertyDataSize(AudioObjectID(kAudioObjectSystemObject), &addr, 0, nil, &propsize)
var deviceIDs = [UInt32](repeating: 0, count: Int(propsize))
AudioObjectGetPropertyData(AudioObjectID(kAudioObjectSystemObject), &addr, 0, nil, &propsize, &deviceIDs)

var transportTypeAddr = AudioObjectPropertyAddress(mSelector: kAudioDevicePropertyTransportType, mScope: kAudioObjectPropertyScopeGlobal, mElement: kAudioObjectPropertyElementMaster)
var transportType: UInt32 = 0

for device in deviceIDs {
AudioObjectGetPropertyData(device, &transportTypeAddr, 0, nil, &propsize, &transportType)
print(transportType)
if transportType == kAudioDeviceTransportTypeAirPlay {
self.device = device
print("found device")
}
}
super.init()
self.getAirPlayOutputs()
print(outputs)
}

func getAirPlayOutputs() {
var addr = AudioObjectPropertyAddress(mSelector: kAudioDevicePropertyDataSources, mScope: kAudioDevicePropertyScopeOutput, mElement: kAudioObjectPropertyElementWildcard)
var propsize: UInt32 = 0
AudioObjectGetPropertyDataSize(self.device, &addr, 0, nil, &propsize)
var sourceIDs = [UInt32](repeating: 0, count: Int(propsize))
AudioObjectGetPropertyData(self.device, &addr, 0, nil, &propsize, &sourceIDs)
for source in sourceIDs {
outputs.append(AirPlayDestination(id: source, airPlayDevice: self.device))
}
}

}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions jmc/Assets.xcassets/AirPlay.imageset/Contents.json
@@ -0,0 +1,24 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "AirPlayAudioIcon.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
2 changes: 2 additions & 0 deletions jmc/Backend/Audio/AudioModule.swift
Expand Up @@ -63,6 +63,7 @@ class AudioModule: NSObject {
var fileManager = FileManager.default
var upcomingTrackURL: URL?
var endOfCurrentTrackFrame: AVAudioFramePosition?
var airplayDeviceHandler: AirPlayDeviceHandler

let verbotenFileTypes = ["m4v", "m4p"]

Expand Down Expand Up @@ -156,6 +157,7 @@ class AudioModule: NSObject {
}

override init() {
self.airplayDeviceHandler = AirPlayDeviceHandler()
super.init()
addListenerBlock(audioObjectPropertyListenerBlock,
onAudioObjectID: AudioObjectID(bitPattern: kAudioObjectSystemObject),
Expand Down
2 changes: 1 addition & 1 deletion jmc/Delegate:Main Window Controller/AppDelegate.swift
Expand Up @@ -37,7 +37,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
mainWindowController!.jumpToCurrentSong()
}
@IBAction func jumpToSelection(_ sender: Any) {
mainWindowController.jumpToSelection()
mainWindowController?.jumpToSelection()
}
@IBAction func toggleAlbumArt(_ sender: Any) {
mainWindowController?.toggleArtwork(self)
Expand Down
13 changes: 9 additions & 4 deletions jmc/Delegate:Main Window Controller/MainWindowController.swift
Expand Up @@ -355,14 +355,19 @@ class MainWindowController: NSWindowController, NSSearchFieldDelegate, NSWindowD
func initAlbumArtwork(for track: Track) {
albumArtViewController?.initAlbumArt(track)
}
@IBAction func airPlayPressed(_ sender: Any) {

}

@IBAction func toggleArtwork(_ sender: AnyObject) {
if artToggle.state == NSOnState {
UserDefaults.standard.set(true, forKey: DEFAULTS_SHOWS_ARTWORK_STRING)
self.artworkTargetView.isHidden = false
} else {
if self.artworkTargetView.isHidden == false {
artToggle.state = NSOffState
UserDefaults.standard.set(false, forKey: DEFAULTS_SHOWS_ARTWORK_STRING)
self.artworkTargetView.isHidden = true
} else {
artToggle.state = NSOnState
UserDefaults.standard.set(true, forKey: DEFAULTS_SHOWS_ARTWORK_STRING)
self.artworkTargetView.isHidden = false
}
}

Expand Down
16 changes: 16 additions & 0 deletions jmc/Delegate:Main Window Controller/MainWindowController.xib
Expand Up @@ -462,11 +462,25 @@
<outlet property="menu" destination="WAr-lr-0sM" id="tZk-Ww-b2z"/>
</connections>
</segmentedControl>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="3zk-MK-Txl">
<rect key="frame" x="332" y="4" width="44" height="25"/>
<constraints>
<constraint firstAttribute="width" constant="44" id="o3L-oL-E1Z"/>
</constraints>
<buttonCell key="cell" type="roundTextured" bezelStyle="texturedRounded" image="AirPlay" imagePosition="overlaps" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="Li0-sK-BT1">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="airPlayPressed:" target="-2" id="usU-lb-Air"/>
</connections>
</button>
</subviews>
<constraints>
<constraint firstAttribute="bottom" secondItem="0eg-hu-JdK" secondAttribute="bottom" constant="6" id="1mf-qn-i1B"/>
<constraint firstItem="qNB-cP-szA" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="20" id="3Zf-1k-4fz"/>
<constraint firstItem="rfk-1e-A3X" firstAttribute="leading" secondItem="aLT-7j-MYS" secondAttribute="trailing" constant="8" id="8hA-tp-cFE"/>
<constraint firstItem="3zk-MK-Txl" firstAttribute="leading" secondItem="mb6-nw-TjG" secondAttribute="trailing" constant="8" id="8uV-bl-nRX"/>
<constraint firstItem="wUv-cJ-CeL" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="3" id="9dD-af-Zpw"/>
<constraint firstItem="r3P-eO-TmU" firstAttribute="top" secondItem="se5-gp-TjO" secondAttribute="top" constant="60" id="FWU-KC-1lo"/>
<constraint firstItem="wUv-cJ-CeL" firstAttribute="leading" secondItem="se5-gp-TjO" secondAttribute="leading" constant="75" id="Gt8-ei-BxH"/>
Expand All @@ -487,6 +501,7 @@
<constraint firstAttribute="bottom" secondItem="mb6-nw-TjG" secondAttribute="bottom" constant="6" id="lba-F2-zcv"/>
<constraint firstItem="FOU-Bi-82q" firstAttribute="centerX" secondItem="se5-gp-TjO" secondAttribute="centerX" id="mfK-fT-Eft"/>
<constraint firstAttribute="bottom" secondItem="aLT-7j-MYS" secondAttribute="bottom" constant="6" id="o6B-h3-TeK"/>
<constraint firstAttribute="bottom" secondItem="3zk-MK-Txl" secondAttribute="bottom" constant="6" id="r5Z-q9-Dl3"/>
<constraint firstItem="aLT-7j-MYS" firstAttribute="leading" secondItem="eg4-23-xqc" secondAttribute="trailing" constant="8" id="tVc-S0-2bd"/>
<constraint firstAttribute="bottom" secondItem="r3P-eO-TmU" secondAttribute="bottom" constant="36" id="vhg-0d-8Gk"/>
<constraint firstAttribute="bottom" secondItem="gzN-xP-Utz" secondAttribute="bottom" constant="6" id="wBw-oE-Tlu"/>
Expand Down Expand Up @@ -521,6 +536,7 @@
</menu>
</objects>
<resources>
<image name="AirPlay" width="18" height="16"/>
<image name="NSAddTemplate" width="11" height="11"/>
<image name="NSFlowViewTemplate" width="18" height="10"/>
<image name="NSPlayTemplate" width="25" height="23"/>
Expand Down

0 comments on commit c135617

Please sign in to comment.