209 lines
6.3 KiB
C++
209 lines
6.3 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: TjdUiAppPlayerModel.h
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2024-06-07
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#ifndef TJD_UI_APP_PLAYER_MODEL_H
|
|
#define TJD_UI_APP_PLAYER_MODEL_H
|
|
|
|
// clang-format off
|
|
#include "TjdUiAppPlayerPresenter.h"
|
|
#include "bts_a2dp_source.h"
|
|
#include "bts_br_gap.h"
|
|
#include "bts_avrcp_controller.h"
|
|
#include "bts_avrcp_target.h"
|
|
#include <cstdint>
|
|
#include "fs_user_common.h"
|
|
#include <osal_list.h>
|
|
#include <list>
|
|
#include "player.h"
|
|
#include "td_type.h"
|
|
// clang-format on
|
|
|
|
namespace TJD {
|
|
|
|
enum
|
|
{
|
|
NORMAL,
|
|
NONE_SONG_PLAY,
|
|
SONG_ALREADY_PLAY,
|
|
SONG_ALREADY_PAUSE,
|
|
SONG_ALREADY_STOP,
|
|
EXECUTE_FUNC_FAILED,
|
|
NO_SUPPORT_SCENE,
|
|
PLAYER_RESPONESE_MAX
|
|
};
|
|
|
|
typedef struct
|
|
{
|
|
td_pvoid stream_hdl;
|
|
uint8_t loc_volume;
|
|
uint8_t play_stat;
|
|
uint8_t dir_forward;
|
|
uint8_t avrcp_button_flag;
|
|
bd_addr_t bd_addr;
|
|
uint8_t reg_cap_auto;
|
|
uint8_t resrv;
|
|
profile_connect_state_t avrcp_srv_conn_stat;
|
|
} BtAvrcpTgInf;
|
|
|
|
class PlayersListGroup
|
|
{
|
|
public:
|
|
PlayersListGroup(){};
|
|
~PlayersListGroup();
|
|
static PlayersListGroup *GetInstance();
|
|
void SetUpListCase();
|
|
char *GetCase(int16_t index);
|
|
void AddCase(PlayerCaseInfo testCaseInfo);
|
|
void RemoveCase(int16_t index);
|
|
std::list<PlayerCaseInfo> &GetCase() { return *playersCaseList_; }
|
|
|
|
private:
|
|
std::list<PlayerCaseInfo> *playersCaseList_{nullptr};
|
|
int GetAllFiles(void);
|
|
void RemoveTargetFile(const char *sliceId);
|
|
};
|
|
|
|
enum class PlayerSource
|
|
{
|
|
PLAYER_SOURCE_PHONE = 0,
|
|
PLAYER_SOURCE_WATCH,
|
|
};
|
|
|
|
class TjdUiAppPlayerModel
|
|
{
|
|
public:
|
|
static TjdUiAppPlayerModel *GetInstance(void);
|
|
void InitBluetoothPlayer(void);
|
|
|
|
int PlayerInit(void);
|
|
void AudioInit(void);
|
|
bool GetAudioInitStatus(void);
|
|
int PlayerStart(void);
|
|
int PlayerStop(void);
|
|
void LoopingPlayout(void); // 下一首
|
|
void PreviousPlayout(void); // 上一首
|
|
|
|
void PhoneAudioPlay(); // 控制手机音频播放
|
|
void PhoneAudioStop(); // 控制手机音频停止
|
|
void PhoneAudioPrevious(); // 控制手机音频上一首
|
|
void PhoneAudioForward(); // 控制手机音频下一首
|
|
|
|
void PlaySwitching(void);
|
|
int GetPlayerState(void);
|
|
int32_t GetPlayerStatus(void);
|
|
void SetBTMusicPlay(avrcp_key_operation_t notification);
|
|
|
|
bool ConnectBtAndLocalPlay(int32_t connCtState, int32_t connTgState);
|
|
void ConnectBtAndLocalPause(int32_t connCtState, int32_t connTgState);
|
|
std::shared_ptr<OHOS::Media::Player> GetPlayerCtr() { return playerCtr_; }
|
|
std::shared_ptr<PlayerInterruptListener> GetPlayerIntrptListener(void) { return playerInterruptListener_; }
|
|
void SetPlayButtonState(bool value) { playButtonState_ = value; }
|
|
bool GetPlayButtonState(void) { return playButtonState_; }
|
|
void ClearActivateAudioInterrupt() { isActivateAudioInterrupt_ = false; }
|
|
|
|
void SetPlayModeAddOne(void)
|
|
{
|
|
if (playerModel_ == PlayMode::SEQUENCE) {
|
|
playerModel_ = PlayMode::REPEATS;
|
|
} else if (playerModel_ == PlayMode::REPEATS) {
|
|
playerModel_ = PlayMode::RANDOM;
|
|
} else if (playerModel_ == PlayMode::RANDOM) {
|
|
playerModel_ = PlayMode::SEQUENCE;
|
|
}
|
|
}
|
|
PlayMode GetPlayMode(void) { return playerModel_; }
|
|
|
|
void SetCurrentIndex(int16_t value) { currentIndex_ = value; }
|
|
int16_t GetCurrentIndex(void) { return currentIndex_; }
|
|
|
|
void SetPlayerUri(std::string src) { uri_ = src; }
|
|
std::string GetPlayerUri(void) { return uri_; }
|
|
|
|
const bd_addr_t *GetLastConnedAddr();
|
|
|
|
uint8_t GetBartteryLevel(void);
|
|
|
|
void SetVolume(int32_t volume);
|
|
int32_t GetA2dpVolume(void);
|
|
int32_t GetLocalVolume(void);
|
|
|
|
// 获取歌曲时长
|
|
uint64_t GetDuration(void) { return duration_; }
|
|
// 获取歌曲当前播放时间
|
|
int64_t GetCurrentPosition(void)
|
|
{
|
|
int64_t position = 0;
|
|
playerCtr_->GetCurrentTime(position);
|
|
return position;
|
|
}
|
|
bool StartHeadsetPlug(void);
|
|
bool StopHeadsetPlug(void);
|
|
osal_list_head *GetHeadsetInfo();
|
|
|
|
void SetPlayerDeviceState(PlayerSource state) { playerDeviceState_ = state; }
|
|
PlayerSource GetPlayerDeviceState(void) { return playerDeviceState_; }
|
|
|
|
void SetPhoneAudioEnable(bool enable);
|
|
|
|
void SetConnectEarpod(bool value) { isConnectEarpod_ = value; }
|
|
bool IsConnectEarpod(void) { return isConnectEarpod_; }
|
|
int ConnectHeadset(const bd_addr_t &addr);
|
|
bool IsConnectHeadset(const bd_addr_t &addr);
|
|
bool UnpairHeadset(const bd_addr_t &addr);
|
|
bool DisconnectHeadset(const bd_addr_t &addr);
|
|
|
|
bool PhoneAudioIsPlaying(void);
|
|
|
|
bool IsConnectBt(void);
|
|
bool IsConnectHeadset(void);
|
|
bool IsConnectPhone(void);
|
|
|
|
void AvrcpCtStatusNotification(avrcp_play_status_t status);
|
|
avrcp_play_status_t GetPhoneAudioPlayStatus(void) { return avrcpPlayStatus_; }
|
|
|
|
private:
|
|
TjdUiAppPlayerModel();
|
|
~TjdUiAppPlayerModel();
|
|
|
|
void InitBtHeadsetEvent();
|
|
void InitBtA2dpSourceEvent();
|
|
void InitBtA2dpSinkEvent();
|
|
void ConncetBtResetButton(void);
|
|
|
|
void SequencePlayout(void);
|
|
void RandomPlayout();
|
|
void NextSong(int16_t index);
|
|
|
|
PlayMode playerModel_{PlayMode::SEQUENCE};
|
|
|
|
char *sliceId{nullptr};
|
|
bool audioInitStatus_{false};
|
|
int16_t currentIndex_{0};
|
|
std::shared_ptr<OHOS::Media::Player> playerCtr_{nullptr};
|
|
std::shared_ptr<OHOS::Media::PlayerCallback> playerCallback_{nullptr};
|
|
|
|
std::shared_ptr<OHOS::Media::Source> source_{nullptr};
|
|
std::string uri_;
|
|
std::map<std::string, std::string> header_;
|
|
int64_t duration_{0};
|
|
bool isActivateAudioInterrupt_{false};
|
|
AudioSession sessionId_;
|
|
std::shared_ptr<PlayerInterruptListener> playerInterruptListener_{nullptr};
|
|
Audio::AudioInterrupt interrupt_;
|
|
bool playButtonState_{false};
|
|
PlayerSource playerDeviceState_{PlayerSource::PLAYER_SOURCE_WATCH};
|
|
bool isConnectEarpod_{false};
|
|
|
|
avrcp_play_status_t avrcpPlayStatus_{avrcp_play_status_t::AVRCP_PLAY_STATUS_STOPPED};
|
|
};
|
|
|
|
} // namespace TJD
|
|
|
|
#endif |