| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #include "embedders/openglui/common/sound_handler.h" | |
| 6 | |
| 7 #include <string.h> | |
| 8 | |
| 9 #include "embedders/openglui/common/log.h" | |
| 10 | |
| 11 // TODO(gram): Clean up this instance pointer; either make the class | |
| 12 // a proper singleton or provide a cleaner way for the static functions | |
| 13 // at the end to access it (those functions are the hooks into the Dart | |
| 14 // native extension). | |
| 15 SoundHandler* instance_ = NULL; | |
| 16 | |
| 17 SoundHandler::SoundHandler() | |
| 18 : samples_() { | |
| 19 instance_ = this; | |
| 20 } | |
| 21 | |
| 22 Sample* SoundHandler::GetSample(const char* path) { | |
| 23 for (samples_t::iterator sp = samples_.begin(); | |
| 24 sp != samples_.end(); | |
| 25 ++sp) { | |
| 26 Sample* sample = (*sp); | |
| 27 if (strcmp(sample->path(), path) == 0) { | |
| 28 LOGI("Returning cached sample %s", path); | |
| 29 return sample; | |
| 30 } | |
| 31 } | |
| 32 Sample* sample = new Sample(path); | |
| 33 if (sample->Load() != 0) { | |
| 34 LOGI("Failed to load sample %s", path); | |
| 35 delete sample; | |
| 36 return NULL; | |
| 37 } | |
| 38 samples_.push_back(sample); | |
| 39 LOGI("Adding sample %s to cache", path); | |
| 40 return sample; | |
| 41 } | |
| 42 | |
| 43 int32_t PlayBackgroundSound(const char* path) { | |
| 44 return instance_->PlayBackground(path); | |
| 45 } | |
| 46 | |
| 47 void StopBackgroundSound() { | |
| 48 instance_->StopBackground(); | |
| 49 } | |
| 50 | |
| 51 int32_t LoadSoundSample(const char* path) { | |
| 52 return instance_->LoadSample(path); | |
| 53 } | |
| 54 | |
| 55 int32_t PlaySoundSample(const char* path) { | |
| 56 return instance_->PlaySample(path); | |
| 57 } | |
| 58 | |
| OLD | NEW |