AndroidStreamSource.cc 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  35. AndroidStreamSource::~AndroidStreamSource() {
  36. stop();
  37. delete [] mFilename;
  38. android_UnLoadMusicTrack();
  39. }
  40. bool AndroidStreamSource::isPlaying() {
  41. return android_isMusicTrackPlaying();
  42. }
  43. bool AndroidStreamSource::start( bool loop ) {
  44. Con::printf("Starting music file: %s", mFilename);
  45. android_LoadMusicTrack( mFilename );
  46. android_StartMusicTrack();
  47. return true;
  48. }
  49. bool AndroidStreamSource::stop() {
  50. android_StopMusicTrack();
  51. android_UnLoadMusicTrack();
  52. return true;
  53. }
  54. bool AndroidStreamSource::setVolume( F32 volume) {
  55. android_setMusicTrackVolume(volume);
  56. return true;
  57. }
  58. AndroidStreamSource* stream = NULL;
  59. ConsoleFunction(playStreamingMusic, void, 2, 2, "")
  60. {
  61. if (stream != NULL)
  62. delete stream;
  63. stream = new AndroidStreamSource(argv[1]);
  64. stream->start();
  65. }