1 /*
2  * Copyright (c) 2022-2022 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_EOS_STATE_H
17 #define HISTREAMER_HIPLAYER_EOS_STATE_H
18 
19 #include "state.h"
20 namespace OHOS {
21 namespace Media {
22 // when eos received
23 class EosState : public State {
24 public:
EosState(StateId stateId,PlayExecutor & executor)25     explicit EosState(StateId stateId, PlayExecutor& executor) : State(stateId, "EosState", executor) {}
26 
27     ~EosState() override = default;
28 
Play()29     std::tuple<ErrorCode, Action> Play() override
30     {
31         MEDIA_LOG_I("play in eos state.");
32         auto ret = executor_.DoSeek(0, Plugin::SeekMode::SEEK_PREVIOUS_SYNC, false);
33         if (ret == ErrorCode::SUCCESS) {
34             return {ErrorCode::SUCCESS, Action::TRANS_TO_PLAYING};
35         } else {
36             MEDIA_LOG_W("seek error in eos state when asked to play");
37             return {ret, Action::ACTION_BUTT};
38         }
39     }
40 
Seek(const Plugin::Any & param)41     std::tuple<ErrorCode, Action> Seek(const Plugin::Any& param) override
42     {
43         MEDIA_LOG_I("seek in eos is useless");
44         return {ErrorCode::ERROR_INVALID_OPERATION, Action::ACTION_BUTT};
45     }
46 
Enter(Intent intent)47     std::tuple<ErrorCode, Action> Enter(Intent intent) override
48     {
49         MEDIA_LOG_I("eos state entered");
50         auto ret = executor_.DoPause();
51         return {ret, Action::ACTION_BUTT};
52     }
53 
Stop()54     std::tuple<ErrorCode, Action> Stop() override
55     {
56         MEDIA_LOG_I("stop eos state");
57         return {ErrorCode::SUCCESS, Action::TRANS_TO_STOPPED};
58     }
59 };
60 } // namespace Media
61 } // namespace OHOS
62 
63 #endif // HISTREAMER_HIPLAYER_EOS_STATE_H
64