1 /* 2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef HISTREAMER_HIPLAYER_PAUSE_STATE_H 17 #define HISTREAMER_HIPLAYER_PAUSE_STATE_H 18 19 #include <memory> 20 #include "foundation/log.h" 21 #include "pipeline/core/error_code.h" 22 #include "play_executor.h" 23 #include "state.h" 24 25 namespace OHOS { 26 namespace Media { 27 class PauseState : public State { 28 public: PauseState(StateId stateId,PlayExecutor & executor)29 explicit PauseState(StateId stateId, PlayExecutor& executor) : State(stateId, "PauseState", executor) 30 { 31 } 32 33 ~PauseState() override = default; 34 Enter(Intent)35 std::tuple<ErrorCode, Action> Enter(Intent) override 36 { 37 MEDIA_LOG_D("Pause state entered."); 38 auto ret = executor_.DoPause(); 39 return {ret, Action::ACTION_BUTT}; 40 } 41 Play()42 std::tuple<ErrorCode, Action> Play() override 43 { 44 MEDIA_LOG_D("Play in pause state."); 45 return {ErrorCode::SUCCESS, Action::TRANS_TO_PLAYING}; 46 } 47 Seek(const Plugin::Any & param)48 std::tuple<ErrorCode, Action> Seek(const Plugin::Any& param) override 49 { 50 MEDIA_LOG_D("Seek in pause state."); 51 std::tuple<ErrorCode, Action> err {ErrorCode::ERROR_INVALID_PARAMETER_TYPE, Action::ACTION_BUTT}; 52 FALSE_RETURN_V(Plugin::Any::IsSameTypeWith<SeekInfo>(param), err); 53 auto info = Plugin::AnyCast<SeekInfo>(param); 54 auto ret = executor_.DoSeek(info.hstTime, info.mode, true); 55 return {ret, Action::ACTION_BUTT}; 56 } 57 Pause()58 std::tuple<ErrorCode, Action> Pause() override 59 { 60 MEDIA_LOG_D("Pause in pause state."); 61 return {ErrorCode::SUCCESS, Action::ACTION_BUTT}; 62 } 63 Resume()64 std::tuple<ErrorCode, Action> Resume() override 65 { 66 MEDIA_LOG_D("Resume in pause state."); 67 return {ErrorCode::SUCCESS, Action::TRANS_TO_PLAYING}; 68 } 69 Stop()70 std::tuple<ErrorCode, Action> Stop() override 71 { 72 MEDIA_LOG_D("Stop called in pause state."); 73 return {ErrorCode::SUCCESS, Action::TRANS_TO_STOPPED}; 74 } 75 }; 76 } // namespace Media 77 } // namespace OHOS 78 #endif 79