Created
January 28, 2016 04:24
-
-
Save DarrellBrogdon/31acf617fbcd303b7db8 to your computer and use it in GitHub Desktop.
Audio Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WatchKit | |
import Foundation | |
import WatchConnectivity | |
// | |
// The WatchKit Interface Controller | |
// | |
class InterfaceController: WKInterfaceController, WCSessionDelegate { | |
var session: WCSession! | |
@IBAction func sendMessage() { | |
let messageToSend = ["Value": "Play Sound"] | |
session.sendMessage(messageToSend, replyHandler: {replyMessage in | |
print("Sending the message") | |
}, errorHandler: {error in | |
print(error) | |
}) | |
} | |
override func awakeWithContext(context: AnyObject?) { | |
super.awakeWithContext(context) | |
// Configure interface objects here. | |
} | |
override func willActivate() { | |
// This method is called when watch view controller is about to be visible to user | |
super.willActivate() | |
if WCSession.isSupported() { | |
session = WCSession.defaultSession() | |
session.delegate = self | |
session.activateSession() | |
} | |
} | |
override func didDeactivate() { | |
// This method is called when watch view controller is no longer visible | |
super.didDeactivate() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import AVFoundation | |
// | |
// A class for playing the sound | |
// | |
class TestSound { | |
let theSoundFile = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sound", ofType: "wav")!) | |
var audioPlayer: AVAudioPlayer! | |
func playSound() { | |
print("Playing test sound") | |
do { | |
self.audioPlayer = try AVAudioPlayer(contentsOfURL: theSoundFile) | |
self.audioPlayer.play() | |
} catch { | |
print("Unable to find sound file") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import WatchConnectivity | |
// | |
// The iOS View Controller | |
// | |
class ViewController: UIViewController, WCSessionDelegate { | |
@IBOutlet weak var messageLabel: UILabel! | |
var session: WCSession! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
if WCSession.isSupported() { | |
session = WCSession.defaultSession() | |
session.delegate = self | |
session.activateSession() | |
} | |
} | |
func session(session: WCSession, didReceiveMessage message: [String : AnyObject], replyHandler: ([String : AnyObject]) -> Void) { | |
let value = message["Value"] as? String | |
let testSound = TestSound() | |
testSound.playSound() | |
dispatch_async(dispatch_get_main_queue(), { | |
self.messageLabel.text = value | |
}) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment