• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 SYSTEM_TONE_PLAYER_H
17 #define SYSTEM_TONE_PLAYER_H
18 
19 #include <string>
20 
21 #include "audio_info.h"
22 
23 namespace OHOS {
24 namespace Media {
25 struct SystemToneOptions {
26     bool muteAudio;
27     bool muteHaptics;
28 };
29 
30 enum class SystemToneState {
31     /** INVALID state */
32     STATE_INVALID = -1,
33     /** Create New instance */
34     STATE_NEW,
35     /** Prepared state */
36     STATE_PREPARED,
37     /** Running state */
38     STATE_RUNNING,
39     /** Stopped state */
40     STATE_STOPPED,
41     /** Released state */
42     STATE_RELEASED,
43     /** Paused state */
44     STATE_PAUSED
45 };
46 
47 class SystemTonePlayer {
48 public:
49     virtual ~SystemTonePlayer() = default;
50 
51     /**
52      * @brief Returns the title of the system tone uri set.
53      *
54      * @return Returns title as string if the title is obtained successfully.
55      * returns an empty string otherwise.
56      * @since 11
57      */
58     virtual std::string GetTitle() const = 0;
59 
60     /**
61      * @brief Prepare the system tone player.
62      *
63      * @return Returns {@link MSERR_OK} if prepare successfully;
64      * returns an error code defined in {@link media_errors.h} otherwise.
65      * @since 11
66      */
67     virtual int32_t Prepare() = 0;
68 
69     /**
70      * @brief Start playing system tone
71      *
72      * @return Returns a non-zero streamID if successful, zero if it fails.
73      * @since 11
74      */
75     virtual int32_t Start() = 0;
76 
77     /**
78      * @brief Start playing system tone with SystemToneOptions
79      *
80      * @param soundID Indicates the sound ID returned by sound pool.
81      * @param systemToneOptions Indicates the mute status of audio and haptic.
82      * @return Returns a non-zero streamID if successful, zero if it fails.
83      * @since 11
84      */
85     virtual int32_t Start(const SystemToneOptions &systemToneOptions) = 0;
86 
87     /**
88      * @brief Stop playing system tone
89      *
90      * @param streamID Indicates the streamID returned by the Start() or Start(SystemToneOptions systemToneOptions).
91      * @return Returns {@link MSERR_OK} if stop playing system tone successfully;
92      * returns an error code defined in {@link media_errors.h} otherwise.
93      * @since 11
94      */
95     virtual int32_t Stop(const int32_t &streamID) = 0;
96 
97     /**
98      * @brief Releases the system tone client resources
99      *
100      * @return Returns {@link MSERR_OK} if the looping parameter is set successfully to player;
101      * returns an error code defined in {@link media_errors.h} otherwise.
102      * @since 11
103      */
104     virtual int32_t Release() = 0;
105 };
106 } // namespace Media
107 } // namespace OHOS
108 #endif // SYSTEM_TONE_PLAYER_H
109