[Tizen] Ensuring that Registry.Unregister is called from the most derived class befor...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / TTSPlayer.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
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
17 namespace Tizen.NUI
18 {
19     using System;
20     using System.Runtime.InteropServices;
21
22     /// <summary>
23     /// The Text-to-speech (TTS) Player.
24     /// </summary>
25     public class TTSPlayer : BaseHandle
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal TTSPlayer(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicManualPINVOKE.TtsPlayer_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TTSPlayer obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         protected override void Dispose(DisposeTypes type)
40         {
41             if (disposed)
42             {
43                 return;
44             }
45
46             if (type == DisposeTypes.Explicit)
47             {
48                 //Called by User
49                 //Release your own managed resources here.
50                 //You should release all of your own disposable objects here.
51             }
52
53             //Release your own unmanaged resources here.
54             //You should not access any managed member here except static instance.
55             //because the execution order of Finalizes is non-deterministic.
56
57             if (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62
63                     //Unreference this instance from Registry.
64                     Registry.Unregister(this);
65
66                     NDalicManualPINVOKE.delete_TtsPlayer(swigCPtr);
67                 }
68                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69             }
70
71             base.Dispose(type);
72         }
73
74         internal TTSPlayer() : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_0(), true)
75         {
76             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
77         }
78
79         /// <summary>
80         /// Gets the singleton of the TtsPlayer for the given mode.
81         /// </summary>
82         /// <param name="mode"> The mode of tts-player. </param>
83         /// <returns> A handle of the Ttsplayer for the given mode. </returns>
84         public static TTSPlayer Get(TTSMode mode)
85         {
86             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_0((int)mode), true);
87             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
88             return ret;
89         }
90
91         /// <summary>
92         /// Gets the singleton of the TtsPlayer for the default mode..
93         /// </summary>
94         /// <returns> A handle of the Ttsplayer for the default mode. </returns>
95         public static TTSPlayer Get()
96         {
97             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Get__SWIG_1(), true);
98             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99             return ret;
100         }
101
102         internal TTSPlayer(TTSPlayer handle) : this(NDalicManualPINVOKE.new_TtsPlayer__SWIG_1(TTSPlayer.getCPtr(handle)), true)
103         {
104             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
105         }
106
107         internal TTSPlayer Assign(TTSPlayer rhs)
108         {
109             TTSPlayer ret = new TTSPlayer(NDalicManualPINVOKE.TtsPlayer_Assign(swigCPtr, TTSPlayer.getCPtr(rhs)), false);
110             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111             return ret;
112         }
113
114         /// <summary>
115         /// Starts playing the audio data synthesized from the specified text.
116         /// </summary>
117         /// <param name="text"> The text to play. </param>
118         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
119         public void Play(string text)
120         {
121             NDalicManualPINVOKE.TtsPlayer_Play(swigCPtr, text);
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123         }
124
125         /// <summary>
126         /// Stops playing the utterance.
127         /// </summary>
128         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
129         public void Stop()
130         {
131             NDalicManualPINVOKE.TtsPlayer_Stop(swigCPtr);
132             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133         }
134
135         /// <summary>
136         /// Pauses the currently playing utterance.
137         /// </summary>
138         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
139         public void Pause()
140         {
141             NDalicManualPINVOKE.TtsPlayer_Pause(swigCPtr);
142             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
143         }
144
145         /// <summary>
146         /// Resumes the previously paused utterance.
147         /// </summary>
148         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
149         public void Resume()
150         {
151             NDalicManualPINVOKE.TtsPlayer_Resume(swigCPtr);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153         }
154
155         /// <summary>
156         /// Gets the current state of the player.
157         /// </summary>
158         /// <returns> The current TTS state. </returns>
159         /// <remarks>The TtsPlayer needs to be initialized.</remarks>
160         public TTSState GetState()
161         {
162             TTSState ret = (TTSState)NDalicManualPINVOKE.TtsPlayer_GetState(swigCPtr);
163             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
164             return ret;
165         }
166
167         /// <summary>
168         /// State changed argument.
169         /// </summary>
170         public class StateChangedEventArgs : EventArgs
171         {
172             public TTSState PrevState
173             {
174                 get;
175                 set;
176             }
177
178             public TTSState NextState
179             {
180                 get;
181                 set;
182             }
183         }
184
185         private StateChangedEventCallbackType _stateChangedEventCallback;
186         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
187         private delegate void StateChangedEventCallbackType(TTSState prevState, TTSState nextState);
188         private event EventHandler<StateChangedEventArgs> _stateChangedEventHandler;
189
190         /// <summary>
191         /// State changed event.
192         /// </summary>
193         public event EventHandler<StateChangedEventArgs> StateChanged
194         {
195             add
196             {
197                 if (_stateChangedEventHandler == null)
198                 {
199                     _stateChangedEventCallback = OnStateChanged;
200                     StateChangedSignal().Connect(_stateChangedEventCallback);
201                 }
202
203                 _stateChangedEventHandler += value;
204             }
205             remove
206             {
207                 _stateChangedEventHandler -= value;
208
209                 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false && _stateChangedEventCallback != null)
210                 {
211                     StateChangedSignal().Disconnect(_stateChangedEventCallback);
212                 }
213             }
214         }
215
216         private void OnStateChanged(TTSState prevState, TTSState nextState)
217         {
218             StateChangedEventArgs e = new StateChangedEventArgs();
219
220             e.PrevState = prevState;
221             e.NextState = nextState;
222
223             if (_stateChangedEventHandler != null)
224             {
225                 _stateChangedEventHandler(this, e);
226             }
227         }
228
229         internal StateChangedSignalType StateChangedSignal()
230         {
231             StateChangedSignalType ret = new StateChangedSignalType(NDalicManualPINVOKE.TtsPlayer_StateChangedSignal(swigCPtr), false);
232             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233             return ret;
234         }
235
236         /// <summary>
237         /// Enumeration for the instance of TTS mode.
238         /// </summary>
239         public enum TTSMode
240         {
241             /// <summary>
242             /// Default mode for normal application.
243             /// </summary>
244             Default = 0,
245             /// <summary>
246             /// Notification mode, such as playing utterance is started or completed.
247             /// </summary>
248             Notification,
249             /// <summary>
250             /// Screen reader mode. <br>
251             /// To help visually impaired users interact with their devices, <br>
252             /// screen reader reads text or graphic elements on the screen using the TTS engine.
253             /// </summary>
254             ScreenReader,
255             /// <summary>
256             /// Number of Mode.
257             /// </summary>
258             ModeNum
259         }
260
261         /// <summary>
262         /// Enumeration for the instance of TTS state.
263         /// </summary>
264         public enum TTSState
265         {
266             /// <summary>
267             /// Player is not available.
268             /// </summary>
269             Unavailable = 0,
270             /// <summary>
271             /// Player is ready to play.
272             /// </summary>
273             Ready,
274             /// <summary>
275             /// Player is playing.
276             /// </summary>
277             Playing,
278             /// <summary>
279             /// Player is paused.
280             /// </summary>
281             Paused
282         }
283
284     }
285
286 }