audio_player.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef JNI_STREAM_PLAYER_H_
  2. #define JNI_STREAM_PLAYER_H_
  3. #include <string>
  4. #include "audio_parameter.h"
  5. namespace base {
  6. class AudioPlayer {
  7. public:
  8. typedef void (*CompletionCallback)(AudioPlayer* player,
  9. int what, void* user_data);
  10. typedef void (*ErrorCallback)(AudioPlayer* player,
  11. int what, const std::string& str, void* user_data);
  12. public:
  13. AudioPlayer(const AudioParameter& parameter);
  14. virtual ~AudioPlayer();
  15. int Play();
  16. int Pause();
  17. int Resume();
  18. int Stop();
  19. int PutSamples(const uint8_t* samples, int length);
  20. /**
  21. * 当前播放位置
  22. */
  23. double GetCurrentPositon();
  24. /**
  25. * 总时长
  26. */
  27. double GetDuration();
  28. /*
  29. * vol 0.0 ~ 1.0
  30. * 平台无关
  31. */
  32. int SetVolume(float volume);
  33. /**
  34. * 平台相关
  35. */
  36. int SetVolume2(int volume);
  37. int SetMute(bool mute);
  38. void set_error_callback(AudioPlayer::ErrorCallback callback, void* user_data);
  39. void set_completion_callback(AudioPlayer::CompletionCallback callback, void* user_data);
  40. /**
  41. * 设置读取超时时间, 防止Play接口长时间阻塞
  42. * 默认5000毫秒
  43. */
  44. void set_read_timeout(int millis);
  45. private:
  46. class Impl;
  47. Impl* impl_;
  48. };
  49. } /* namespace fy */
  50. extern "C" base::AudioPlayer* CreateAudioPlayer();
  51. extern "C" void DestroyAudioPlayer(base::AudioPlayer* stream_player);
  52. /**
  53. * 当所有的StreamPlayer停止播放后,将关闭音频输出设备
  54. * 默认延迟5000毫秒关闭
  55. * @param millis 延迟时间 (毫秒)
  56. */
  57. extern "C" void SetAudioPlayerDisableAudioOutputDeviceDelayed(int millis);
  58. struct StreamPlayerMuteHandler {
  59. /**
  60. * 播放器设置是否静音
  61. * @param mute
  62. * @return
  63. */
  64. int (*SetMute)(bool mute);
  65. /**
  66. * 是否静音,静音返回true
  67. * @return
  68. */
  69. bool (*GetMute)();
  70. };
  71. extern "C" void SetAudioPlayerMuteHandler(const StreamPlayerMuteHandler& handler);
  72. #endif /* JNI_STREAM_PLAYER_H_ */