media_player.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * media_player.h
  3. *
  4. * Created on: 2022年5月26日
  5. * Author: pengzc
  6. */
  7. #ifndef JNI_VOIP_MEDIA_PLAYER_H_
  8. #define JNI_VOIP_MEDIA_PLAYER_H_
  9. #include "audio_player.h"
  10. namespace base {
  11. class MediaPlayer {
  12. public:
  13. typedef void (*CompletionCallback)(MediaPlayer* player,
  14. int what, void* user_data);
  15. typedef void (*ErrorCallback)(MediaPlayer* player,
  16. int what, const std::string& str, void* user_data);
  17. typedef int (*AudioCallback)(MediaPlayer* player,
  18. uint8_t* data, int length, void* user_data);
  19. MediaPlayer();
  20. virtual ~MediaPlayer();
  21. int Play(const std::string& url);
  22. /**
  23. *
  24. * @param url 文件或者链接
  25. * @param headers 指定HTTP协议的Header字段
  26. * 例如
  27. * IP直连,绕过DNS, headers 指定Host字段
  28. * Host: download.flythings.cn
  29. *
  30. * @param timeout_millis 读取超时时间,默认5000毫秒
  31. * @return 成功返回0
  32. */
  33. int Play(const std::string& url, const std::string& headers, int timeout_millis);
  34. int Pause();
  35. int Resume();
  36. int Stop();
  37. /**
  38. * 当前播放位置
  39. */
  40. double GetCurrentPositon();
  41. /**
  42. * 总时长
  43. */
  44. double GetDuration();
  45. void SetErrorCallback(MediaPlayer::ErrorCallback callback, void* user_data);
  46. void SetCompletionCallback(MediaPlayer::CompletionCallback callback, void* user_data);
  47. void SetAudioCallback(MediaPlayer::AudioCallback callback, void* user_data);
  48. /**
  49. * 设置视频区域
  50. */
  51. void SetVideoRectangle(int x, int y, int w, int h);
  52. private:
  53. class Impl;
  54. Impl* impl_;
  55. };
  56. } /* namespace base */
  57. #endif /* JNI_VOIP_MEDIA_PLAYER_H_ */