From f44ead2408dab3f0a07fec13de5e119fd4048020 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 6 Apr 2018 11:09:34 +0100 Subject: [PATCH] Fix InAppPurchasesDemo example --- examples/Utilities/InAppPurchasesDemo.h | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/examples/Utilities/InAppPurchasesDemo.h b/examples/Utilities/InAppPurchasesDemo.h index 7800aa22d3..d70c78afe3 100644 --- a/examples/Utilities/InAppPurchasesDemo.h +++ b/examples/Utilities/InAppPurchasesDemo.h @@ -380,13 +380,11 @@ public: setInterceptsMouseClicks (! hasBeenPurchased, ! hasBeenPurchased); - auto imageFile = getAssetsDirectory().getChildFile ("Purchases").getChildFile (imageResourceName); - + if (auto* assetStream = createAssetInputStream (String ("Purchases/" + String (imageResourceName)).toRawUTF8())) { - ScopedPointer imageData (imageFile.createInputStream()); + ScopedPointer fileStream (assetStream); - if (imageData.get() != nullptr) - avatar = PNGImageFormat().decodeImage (*imageData); + avatar = PNGImageFormat().decodeImage (*fileStream); } } } @@ -552,17 +550,20 @@ private: //============================================================================== void playStopPhrase() { - MemoryOutputStream resourceName; - auto idx = voiceListBox.getSelectedRow(); if (isPositiveAndBelow (idx, soundNames.size())) { - resourceName << soundNames[idx] << phraseListBox.getSelectedRow() << ".ogg"; + auto assetName = "Purchases/" + soundNames[idx] + String (phraseListBox.getSelectedRow()) + ".ogg"; - auto file = getAssetsDirectory().getChildFile ("Purchases").getChildFile (resourceName.toString().toRawUTF8()); + if (auto* assetStream = createAssetInputStream (assetName.toRawUTF8())) + { + ScopedPointer fileStream (assetStream); - if (file.exists()) - player.play (file); + currentPhraseData.reset(); + fileStream->readIntoMemoryBlock (currentPhraseData); + + player.play (currentPhraseData.getData(), currentPhraseData.getSize()); + } } } @@ -571,7 +572,7 @@ private: Label phraseLabel { "phraseLabel", NEEDS_TRANS ("Phrases:") }; ListBox phraseListBox { "phraseListBox" }; - ScopedPointer phraseModel { new PhraseModel() }; + ScopedPointer phraseModel { new PhraseModel() }; TextButton playStopButton { "Play" }; SoundPlayer player; @@ -580,7 +581,9 @@ private: Label voiceLabel { "voiceLabel", NEEDS_TRANS ("Voices:") }; ListBox voiceListBox { "voiceListBox" }; - ScopedPointer voiceModel { new VoiceModel (purchases) }; + ScopedPointer voiceModel { new VoiceModel (purchases) }; + + MemoryBlock currentPhraseData; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InAppPurchasesDemo) };