Browse Source

Fix InAppPurchasesDemo example

tags/2021-05-28
ed 7 years ago
parent
commit
f44ead2408
1 changed files with 16 additions and 13 deletions
  1. +16
    -13
      examples/Utilities/InAppPurchasesDemo.h

+ 16
- 13
examples/Utilities/InAppPurchasesDemo.h View File

@@ -380,13 +380,11 @@ public:
setInterceptsMouseClicks (! hasBeenPurchased, ! hasBeenPurchased); setInterceptsMouseClicks (! hasBeenPurchased, ! hasBeenPurchased);
auto imageFile = getAssetsDirectory().getChildFile ("Purchases").getChildFile (imageResourceName);
if (auto* assetStream = createAssetInputStream (String ("Purchases/" + String (imageResourceName)).toRawUTF8()))
{ {
ScopedPointer<FileInputStream> imageData (imageFile.createInputStream());
ScopedPointer<InputStream> fileStream (assetStream);
if (imageData.get() != nullptr)
avatar = PNGImageFormat().decodeImage (*imageData);
avatar = PNGImageFormat().decodeImage (*fileStream);
} }
} }
} }
@@ -552,17 +550,20 @@ private:
//============================================================================== //==============================================================================
void playStopPhrase() void playStopPhrase()
{ {
MemoryOutputStream resourceName;
auto idx = voiceListBox.getSelectedRow(); auto idx = voiceListBox.getSelectedRow();
if (isPositiveAndBelow (idx, soundNames.size())) if (isPositiveAndBelow (idx, soundNames.size()))
{ {
resourceName << soundNames[idx] << phraseListBox.getSelectedRow() << ".ogg";
auto assetName = "Purchases/" + soundNames[idx] + String (phraseListBox.getSelectedRow()) + ".ogg";
if (auto* assetStream = createAssetInputStream (assetName.toRawUTF8()))
{
ScopedPointer<InputStream> fileStream (assetStream);
auto file = getAssetsDirectory().getChildFile ("Purchases").getChildFile (resourceName.toString().toRawUTF8());
currentPhraseData.reset();
fileStream->readIntoMemoryBlock (currentPhraseData);
if (file.exists())
player.play (file);
player.play (currentPhraseData.getData(), currentPhraseData.getSize());
}
} }
} }
@@ -571,7 +572,7 @@ private:
Label phraseLabel { "phraseLabel", NEEDS_TRANS ("Phrases:") }; Label phraseLabel { "phraseLabel", NEEDS_TRANS ("Phrases:") };
ListBox phraseListBox { "phraseListBox" }; ListBox phraseListBox { "phraseListBox" };
ScopedPointer<ListBoxModel> phraseModel { new PhraseModel() };
ScopedPointer<ListBoxModel> phraseModel { new PhraseModel() };
TextButton playStopButton { "Play" }; TextButton playStopButton { "Play" };
SoundPlayer player; SoundPlayer player;
@@ -580,7 +581,9 @@ private:
Label voiceLabel { "voiceLabel", NEEDS_TRANS ("Voices:") }; Label voiceLabel { "voiceLabel", NEEDS_TRANS ("Voices:") };
ListBox voiceListBox { "voiceListBox" }; ListBox voiceListBox { "voiceListBox" };
ScopedPointer<VoiceModel> voiceModel { new VoiceModel (purchases) };
ScopedPointer<VoiceModel> voiceModel { new VoiceModel (purchases) };
MemoryBlock currentPhraseData;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InAppPurchasesDemo) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (InAppPurchasesDemo)
}; };

Loading…
Cancel
Save