void initDevice(Object sender, RoutedEventArgs e) { if (callControls == null) { try { callControls = Windows.Media.Devices.CallControl.GetDefault(); if (callControls != null) { // Add the event listener to listen for the various button presses callControls.AnswerRequested += new Windows.Media.Devices.CallControlEventHandler(answerButton); callControls.HangUpRequested += new Windows.Media.Devices.CallControlEventHandler(hangupButton); callControls.AudioTransferRequested += new Windows.Media.Devices.CallControlEventHandler(audiotransferButton); callControls.RedialRequested += new Windows.Media.Devices.RedialRequestedEventHandler(redialButton); callControls.DialRequested += new Windows.Media.Devices.DialRequestedEventHandler(dialButton); enableIncomingCallButton(); disableInitializeButton(); dispatchMessage("Call Controls Initialized"); } else { dispatchMessage("Call Controls Failed to Initialize"); } } catch (Exception exception) { dispatchMessage("Call Controls Failed to Initialized in Try Catch" + exception.Message.ToString()); } } }
void hangupButton(Windows.Media.Devices.CallControl sender) { // Hang up request received. The application should end the active call and stop // streaming to the headset dispatchMessage("Hangup requested"); callControls.EndCall(callToken); enableIncomingCallButton(); disableHangUpButton(); stopAudioElement(); callToken = 0; }
void answerButton(Windows.Media.Devices.CallControl sender) { // When the answer button is pressed indicate to the device that the call was answered // and start a song on the headset (this is done by streaming music to the bluetooth // device in this sample) dispatchMessage("Answer Requested: " + callToken.ToString()); callControls.IndicateActiveCall(callToken); SetAudioSource(); enableHangUpButton(); playAudioElement(); }
void dialButton(Windows.Media.Devices.CallControl sender, Windows.Media.Devices.DialRequestedEventArgs dialRequestedEventArgs) { // A device may send a dial request by either sending a URI or if it is a speed dial, // an integer with the number to dial. if (dialRequestedEventArgs.Contact.GetType() == typeof(UInt32)) { dispatchMessage("Dial requested: " + dialRequestedEventArgs.Contact.ToString()); dialRequestedEventArgs.Handled(); } else { // Dialing a URI Uri uri = (Uri)dialRequestedEventArgs.Contact; if (uri.Scheme.Equals("tel", StringComparison.OrdinalIgnoreCase)) { string host = uri.Host; string path = uri.PathAndQuery; dispatchMessage("Dial requested: " + path); } } }
void redialButton(Windows.Media.Devices.CallControl sender, Windows.Media.Devices.RedialRequestedEventArgs redialRequestedEventArgs) { // Handle the redial request here. Indicate to the device that the request was handled. dispatchMessage("Redial Requested"); redialRequestedEventArgs.Handled(); }
void audiotransferButton(Windows.Media.Devices.CallControl sender) { // Handle the audio transfer request here enableHangUpButton(); dispatchMessage("Audio Transfer Requested"); }