AndroidStreamSource.cc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "AndroidStreamSource.h"
  23. extern void android_LoadMusicTrack( const char *mFilename );
  24. extern void android_UnLoadMusicTrack();
  25. extern bool android_isMusicTrackPlaying();
  26. extern void android_StartMusicTrack();
  27. extern void android_StopMusicTrack();
  28. extern void android_setMusicTrackVolume(F32 volume);
  29. AndroidStreamSource::AndroidStreamSource(const char *filename) {
  30. this->registerObject();
  31. int len = dStrlen( filename );
  32. mFilename = new char[len + 1];
  33. dStrcpy( mFilename, filename );
  34. android_LoadMusicTrack( mFilename );
  35. }
  36. AndroidStreamSource::~AndroidStreamSource() {
  37. stop();
  38. delete [] mFilename;
  39. android_UnLoadMusicTrack();
  40. }
  41. bool AndroidStreamSource::isPlaying() {
  42. return android_isMusicTrackPlaying();
  43. }
  44. bool AndroidStreamSource::start( bool loop ) {
  45. android_LoadMusicTrack( mFilename );
  46. android_StartMusicTrack();
  47. if( !loop ) {
  48. //stop at end
  49. android_StopMusicTrack();
  50. Con::executef(1,"onAndroidStreamEnd");
  51. }
  52. return true;
  53. }
  54. bool AndroidStreamSource::stop() {
  55. android_StopMusicTrack();
  56. android_UnLoadMusicTrack();
  57. return true;
  58. }
  59. bool AndroidStreamSource::setVolume( F32 volume) {
  60. android_setMusicTrackVolume(volume);
  61. return true;
  62. }