mcu_hi3321_watch/tjd/ui/app/main/online_wf/TjdUiAppOnlineWfVideoPage.h
2025-05-26 20:15:20 +08:00

158 lines
4.6 KiB
C++

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
*
* Description:
*
* Author: huangshuyi
*
* Create: 2024-8
*--------------------------------------------------------------------------*/
#ifndef TJDUI_ONLINE_WF_VIDEO_PAGE_H
#define TJDUI_ONLINE_WF_VIDEO_PAGE_H
#include <string>
#include <time.h>
#include "components/ui_view.h"
#include "sys/time.h"
#include <string>
#include "cJSON.h"
#include "media_thread_adapt.h"
#include "ui_lite_surface_view.h"
#include "player.h"
#include "audio_manager.h"
#include "audio_base_type.h"
#include "player.h"
using namespace Audio;
using namespace OHOS::Media;
using OHOS::Media::Player;
namespace TJD {
class TjdUiVideoCommon : public OHOS::HeapBase
{
public:
TjdUiVideoCommon(OHOS::Surface *surface, std::string uri, bool isPureVideo)
:surface_(surface), uri_(uri), isPureVideo_(isPureVideo){}
~TjdUiVideoCommon(){ DestroyVideoPlaySource(); }
int32_t StartVideoPlay(void);
int32_t StopVideoPlay(void);
int32_t PauseVideoPlay(void);
int32_t ResumeVideoPlay(void);
int32_t GetDumpInfo(OHOS::Media::PlayerDebugInfo *playerInfo);
void SetVideoPlayLoop(bool isLoop);
void SetSyncExitMode(bool isSyncExitMode);
bool IsExitCompletely(void);
OHOS::Surface *surface_ = nullptr;
AudioInterrupt interrupt_;
AudioSession sessionId_ = AUDIO_SESSION_ID_NONE;
MediaMutexHandle mutex_ = nullptr;
MediaThreadCondHandle cond_ = nullptr;
MediaThreadIdHandle threadHandle_ = nullptr;
shared_ptr<OHOS::Media::Player> player_ = nullptr;
int32_t fd_ = -1;
uint64_t offset_ = 0;
std::string uri_ = "";
bool isPause_ = false;
bool isPlayed_ = false;
bool isLoop_ = true;
bool isEntered_ = false;
bool isExited_ = false;
bool playError_ = false;
bool needSendBackgroundFrame_ = true;
bool isPlaybackCompleted_ = false;
bool isPlaybackStopped_ = false;
bool interruptHintStop_ = false;
bool isPureVideo_ = false;
// static TjdUiVideoCommon *play;
private:
void DestroyVideoPlaySource(void);
static void *VideoPlayThread(void *arg);
bool isSyncExitMode_ = false;
};
class TjdUiAppOnlineWfVideoPage : public OHOS::HeapBase {
public:
TjdUiAppOnlineWfVideoPage(OHOS::UIView* parent, std::string uri, std::string previewPath);
virtual ~TjdUiAppOnlineWfVideoPage();
OHOS::UIView *GetView(void);
TjdUiVideoCommon *videoPlay_ = nullptr;
class VideoPlayerInterruptListener : public Audio::InterruptListener
{
public:
explicit VideoPlayerInterruptListener(TjdUiVideoCommon *videoPlay) : videoPlay_(videoPlay) {}
~VideoPlayerInterruptListener() {};
void OnInterrupt(int32_t type, int32_t hint) override
{
if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE) {
}
if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_RESUME) {
}
if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP) {
MediaMutexLock(videoPlay_->mutex_);
videoPlay_->interruptHintStop_ = true;
MediaThreadCondSignal(videoPlay_->cond_);
MediaMutexUnLock(videoPlay_->mutex_);
}
if (type == INTERRUPT_TYPE_END && hint == INTERRUPT_HINT_STOP) {
}
}
private:
TjdUiVideoCommon *videoPlay_;
};
class VideoPlayCallback : public PlayerCallback
{
public:
explicit VideoPlayCallback(TjdUiVideoCommon *videoPlay) : videoPlay_(videoPlay) {}
~VideoPlayCallback() {}
void OnPlaybackComplete()
{
MediaMutexLock(videoPlay_->mutex_);
videoPlay_->isPlaybackCompleted_ = true;
MediaThreadCondSignal(videoPlay_->cond_);
MediaMutexUnLock(videoPlay_->mutex_);
}
void OnError(int32_t errorType, int32_t errorCode)
{
if (errorType != PlayerErrorType::PLAYER_ERROR_UNKNOWN) {
return;
}
if (errorCode == PlayerErrorCode::PLAYER_ERROR_CODE_AUD_PLAY_FAIL) {
MediaMutexLock(videoPlay_->mutex_);
videoPlay_->playError_ = true;
MediaThreadCondSignal(videoPlay_->cond_);
MediaMutexUnLock(videoPlay_->mutex_);
}
}
void OnInfo(int32_t type, int32_t extra) {}
void OnRewindToComplete() {}
private:
TjdUiVideoCommon *videoPlay_;
};
private:
bool InitView(void);
OHOS::UIView *Parent_{nullptr};
OHOS::UILiteSurfaceView *surfaceView_ = nullptr;
OHOS::ColorType colorKey_;
std::string uri_;
std::string previewPath_;
};
} // namespace OHOS
#endif // MAIN_CLOCK_VIEW_H