libmediaplayer.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #include "libmediaplayer.h"
  2. #include "SpBase.h"
  3. #include "player.h"
  4. void __dbg(const char* fmt, ...)
  5. {
  6. Dbg(fmt);
  7. }
  8. class libmediaplayer_impl
  9. {
  10. private:
  11. CMediaHostApi* m_pHostApi;
  12. CMediaPlayer* m_Player;
  13. public:
  14. libmediaplayer_impl(CMediaHostApi* pHostApi) {
  15. m_pHostApi = pHostApi;
  16. m_Player = new CMediaPlayer();
  17. }
  18. ~libmediaplayer_impl()
  19. {
  20. m_pHostApi = NULL;
  21. delete m_Player;
  22. m_Player = NULL;
  23. }
  24. bool isStop() { return false; }
  25. static void __cb_play_finished(void* user_data)
  26. {
  27. Dbg("callback play finished.");
  28. libmediaplayer_impl* pthis = static_cast<libmediaplayer_impl*>(user_data);
  29. if (NULL != pthis)
  30. {
  31. pthis->PlayMediaFinished();
  32. }
  33. }
  34. void StartPlayVideo(const char* pVideoDir, const char* pNamePrefix = NULL, int nVideoCount = 1)
  35. {
  36. LOG_FUNCTION();
  37. play_media_callback_t cb;
  38. cb.cb_play_media_finished = &__cb_play_finished;
  39. cb.user_data = this;
  40. rvc_media_player_param_t t_param;
  41. t_param.p_input_file = (char*)pNamePrefix;
  42. t_param.cb = &cb;
  43. t_param.picon_path = "D:/run/version/0.0.2.0/bin/rvc_media_player_64px.bmp";
  44. t_param.eType = eVideo_Type;
  45. t_param.playlog = __dbg;
  46. //player_start_play_media(&t_param);
  47. if (0 == m_Player->Init(&t_param))
  48. {
  49. m_Player->StartMediaPlay();
  50. }
  51. }
  52. void StartPlayLocalAudio(const char* pAudioNames)
  53. {
  54. LOG_FUNCTION();
  55. play_media_callback_t cb;
  56. cb.cb_play_media_finished = &__cb_play_finished;
  57. cb.user_data = this;
  58. rvc_media_player_param_t t_param;
  59. t_param.p_input_file = (char*)pAudioNames;
  60. t_param.cb = &cb;
  61. t_param.picon_path = "D:/run/version/0.0.2.0/bin/rvc_media_player_64px.bmp";
  62. t_param.eType = eVideo_Type;
  63. t_param.playlog = __dbg;
  64. //player_start_play_media(&t_param);
  65. if (0 == m_Player->Init(&t_param))
  66. {
  67. m_Player->StartMediaPlay();
  68. }
  69. }
  70. void StartPlayLocalVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  71. {
  72. }
  73. void Close()
  74. {
  75. }
  76. bool checkIsPlay(void* curThreadId)
  77. {
  78. bool bret = false;
  79. int64_t iThreadId = m_Player->GetMediaPlayingThreadId();
  80. if (0 != iThreadId)
  81. {
  82. bret = true;
  83. curThreadId = &iThreadId;
  84. }
  85. return bret;
  86. }
  87. bool checkIsStop()
  88. {
  89. return true;
  90. }
  91. //VOID PlayMedia(CWmpPlayConfig& config);
  92. bool StopPlay()
  93. {
  94. m_Player->StopMediaPlay();
  95. return true;
  96. }
  97. void SetVolume(int nVolume)
  98. {
  99. if (m_Player->GetPlayingFlag())
  100. {
  101. m_Player->SetVolume(nVolume);
  102. }
  103. }
  104. void StartPlaySalesRecordVideo(int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char* pVideoDir, const char* pNamePrefix = NULL, int nVideoCount = 1)
  105. {
  106. }
  107. void PlayMediaFinished()
  108. {
  109. m_pHostApi->Debug("PlayMediaFinished!");
  110. }
  111. };
  112. Clibmediaplayer::Clibmediaplayer(CMediaHostApi* pHostApi)
  113. {
  114. m_pImpl = new libmediaplayer_impl(pHostApi);
  115. return;
  116. }
  117. Clibmediaplayer::~Clibmediaplayer()
  118. {
  119. delete m_pImpl;
  120. m_pImpl = NULL;
  121. }
  122. void Clibmediaplayer::PlayVideo(const char* pVideoDir, const char* pNamePrefix, int nVideoCount)
  123. {
  124. m_pImpl->StartPlayVideo(pVideoDir, pNamePrefix, nVideoCount);
  125. }
  126. void Clibmediaplayer::PlayLocalAudio(const char* pAudioNames)
  127. {
  128. m_pImpl->StartPlayLocalAudio(pAudioNames);
  129. }
  130. void Clibmediaplayer::PlayLocalVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  131. {
  132. m_pImpl->StartPlayLocalVideo(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  133. }
  134. bool Clibmediaplayer::checkIsPlay(void* curThreadId)
  135. {
  136. return m_pImpl->checkIsPlay(curThreadId);
  137. }
  138. bool Clibmediaplayer::checkIsStop()
  139. {
  140. return m_pImpl->isStop();
  141. }
  142. VOID Clibmediaplayer::PlayMedia(CMediaPlayConfig& config)
  143. {
  144. //m_pImpl->StartPlayMedia(config);
  145. }
  146. void Clibmediaplayer::Close()
  147. {
  148. m_pImpl->StopPlay();
  149. }
  150. void Clibmediaplayer::SetVolume(int nVolume)
  151. {
  152. m_pImpl->SetVolume(nVolume);
  153. }
  154. void Clibmediaplayer::PlaySalesRecordVideo(int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char* pVideoDir, const char* pNamePrefix, int nVideoCount)
  155. {
  156. m_pImpl->StartPlaySalesRecordVideo(nWndX, nWndY, nWndWidth, nWndHeight, pVideoDir, pNamePrefix, nVideoCount);
  157. }