atraczyk | 593926f | 2016-12-06 16:02:30 -0500 | [diff] [blame] | 1 | /**************************************************************************
|
| 2 | * Copyright (C) 2016 by Savoir-faire Linux *
|
| 3 | * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
|
| 4 | * Author: Traczyk Andreas <traczyk.andreas@savoirfairelinux.com> *
|
| 5 | * *
|
| 6 | * This program is free software; you can redistribute it and/or modify *
|
| 7 | * it under the terms of the GNU General Public License as published by *
|
| 8 | * the Free Software Foundation; either version 3 of the License, or *
|
| 9 | * (at your option) any later version. *
|
| 10 | * *
|
| 11 | * This program is distributed in the hope that it will be useful, *
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 | * GNU General Public License for more details. *
|
| 15 | * *
|
| 16 | * You should have received a copy of the GNU General Public License *
|
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
| 18 | **************************************************************************/
|
| 19 | #include "pch.h"
|
| 20 |
|
| 21 | using namespace Windows::UI::Core;
|
| 22 |
|
| 23 | using namespace RingClientUWP;
|
| 24 |
|
| 25 | Ringtone::Ringtone(String^ fileName)
|
| 26 | {
|
| 27 | fileName_ = fileName;
|
| 28 | CreateGraph()
|
| 29 | .then([this](task<void> t) {
|
| 30 | t.get();
|
| 31 | CreateDefaultDeviceOutputNode()
|
| 32 | .then([this](task<void> t) {
|
| 33 | t.get();
|
| 34 | CreateFileInputNode()
|
| 35 | .then([](task<void> t) {
|
| 36 | t.get();
|
| 37 | });
|
| 38 | });
|
| 39 | });
|
| 40 | }
|
| 41 |
|
| 42 | void
|
| 43 | Ringtone::Start()
|
| 44 | {
|
| 45 | _graph->Start();
|
| 46 | }
|
| 47 |
|
| 48 | void
|
| 49 | Ringtone::Stop()
|
| 50 | {
|
| 51 | _graph->Stop();
|
| 52 | _graph->ResetAllNodes();
|
| 53 | }
|
| 54 |
|
| 55 | task<void>
|
| 56 | Ringtone::CreateGraph()
|
| 57 | {
|
| 58 | AudioGraphSettings^ settings = ref new AudioGraphSettings(Windows::Media::Render::AudioRenderCategory::Media);
|
| 59 | return create_task(AudioGraph::CreateAsync(settings))
|
| 60 | .then([=](CreateAudioGraphResult^ result){
|
| 61 | if (result->Status != AudioGraphCreationStatus::Success) {
|
| 62 | MSG_("CreateGraph failed");
|
| 63 | }
|
| 64 | _graph = result->Graph;
|
| 65 | });
|
| 66 | }
|
| 67 |
|
| 68 | task<void>
|
| 69 | Ringtone::CreateDefaultDeviceOutputNode()
|
| 70 | {
|
| 71 | return create_task(_graph->CreateDeviceOutputNodeAsync())
|
| 72 | .then([=](CreateAudioDeviceOutputNodeResult^ result){
|
| 73 | if (result->Status != AudioDeviceNodeCreationStatus::Success) {
|
| 74 | MSG_("CreateDefaultDeviceOutputNode failed");
|
| 75 | }
|
| 76 | _deviceOutputNode = result->DeviceOutputNode;
|
| 77 | });
|
| 78 | }
|
| 79 |
|
| 80 | task<void>
|
| 81 | Ringtone::CreateFileInputNode()
|
| 82 | {
|
| 83 | Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
|
| 84 | Windows::Storage::StorageFolder^ installedLocation = package->InstalledLocation;
|
| 85 | return create_task(installedLocation->GetFolderAsync("Assets"))
|
| 86 | .then([=](StorageFolder^ assetsFolder){
|
| 87 | create_task(assetsFolder->GetFileAsync(fileName_))
|
| 88 | .then([=](StorageFile^ ringtoneFile){
|
| 89 | // functions as a Background task but will force a SMTC panel into the thumbnail
|
| 90 | //mp = ref new MediaPlayer();
|
| 91 | //mp->Source = MediaSource::CreateFromStorageFile(ringtoneFile);
|
| 92 | ////mp->CommandManager->IsEnabled = false;
|
| 93 | //mp->IsLoopingEnabled = true;
|
| 94 | //mp->Play();
|
| 95 | create_task(_graph->CreateFileInputNodeAsync(ringtoneFile))
|
| 96 | .then([=](CreateAudioFileInputNodeResult^ result){
|
| 97 | if (result->Status != AudioFileNodeCreationStatus::Success) {
|
| 98 | MSG_("CreateFileInputNode failed");
|
| 99 | }
|
| 100 | _fileInputNode = result->FileInputNode;
|
| 101 | _fileInputNode->LoopCount = nullptr;
|
| 102 | _fileInputNode->AddOutgoingConnection(_deviceOutputNode);
|
| 103 | });
|
| 104 | });
|
| 105 | });
|
| 106 | } |