Setting since_tizen 3/4 on Tizen.NET API
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia.MediaPlayer / Player / Player.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 using System;
17 using System.Threading.Tasks;
18 using System.Runtime.InteropServices;
19 using System.Diagnostics;
20 using System.IO;
21 using System.Threading;
22 using static Interop;
23 using System.ComponentModel;
24
25 namespace Tizen.Multimedia
26 {
27     internal static class PlayerLog
28     {
29         internal const string Tag = "Tizen.Multimedia.Player";
30     }
31
32     /// <summary>
33     /// Provides the ability to control media playback.
34     /// </summary>
35     /// <remarks>
36     /// The player provides functions to play a media content.
37     /// It also provides functions to adjust the configurations of the player such as playback rate, volume, looping etc.
38     /// Note that only one video player can be played at one time.
39     /// </remarks>
40     public partial class Player : IDisposable, IDisplayable<PlayerErrorCode>
41     {
42         private PlayerHandle _handle;
43
44         /// <summary>
45         /// Initializes a new instance of the <see cref="Player"/> class.
46         /// </summary>
47         /// <since_tizen> 3 </since_tizen>
48         public Player()
49         {
50             NativePlayer.Create(out _handle).ThrowIfFailed("Failed to create player");
51
52             Debug.Assert(_handle != null);
53
54             RetrieveProperties();
55
56             if (Features.IsSupported(Features.AudioEffect))
57             {
58                 _audioEffect = new AudioEffect(this);
59             }
60
61             if (Features.IsSupported(Features.RawVideo))
62             {
63                 RegisterVideoFrameDecodedCallback();
64             }
65
66             DisplaySettings = PlayerDisplaySettings.Create(this);
67         }
68
69         internal void ValidatePlayerState(params PlayerState[] desiredStates)
70         {
71             Debug.Assert(desiredStates.Length > 0);
72
73             ValidateNotDisposed();
74
75             var curState = State;
76             if (curState.IsAnyOf(desiredStates))
77             {
78                 return;
79             }
80
81             throw new InvalidOperationException($"The player is not in a valid state. " +
82                 $"Current State : { curState }, Valid State : { string.Join(", ", desiredStates) }.");
83         }
84
85         #region Dispose support
86         private bool _disposed;
87
88         /// <summary>
89         /// Releases all resources used by the current instance.
90         /// </summary>
91         /// <since_tizen> 3 </since_tizen>
92         public void Dispose()
93         {
94             Dispose(true);
95         }
96
97         private void Dispose(bool disposing)
98         {
99             if (!_disposed)
100             {
101                 ReplaceDisplay(null);
102
103                 if (_source != null)
104                 {
105                     try
106                     {
107                         _source.DetachFrom(this);
108                     }
109                     catch (Exception e)
110                     {
111                         Log.Error(PlayerLog.Tag, e.ToString());
112                     }
113                 }
114                 _source = null;
115
116                 if (_handle != null)
117                 {
118                     _handle.Dispose();
119                 }
120                 _disposed = true;
121             }
122         }
123
124         internal void ValidateNotDisposed()
125         {
126             if (_disposed)
127             {
128                 Log.Warn(PlayerLog.Tag, "player was disposed");
129                 throw new ObjectDisposedException(nameof(Player));
130             }
131         }
132
133         internal bool IsDisposed => _disposed;
134         #endregion
135
136         #region Methods
137
138         /// <summary>
139         /// Gets the streaming download progress.
140         /// </summary>
141         /// <returns>The <see cref="DownloadProgress"/> containing current download progress.</returns>
142         /// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
143         /// <exception cref="InvalidOperationException">
144         ///     The player is not streaming.<br/>
145         ///     -or-<br/>
146         ///     The player is not in the valid state.
147         ///     </exception>
148         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
149         /// <since_tizen> 3 </since_tizen>
150         public DownloadProgress GetDownloadProgress()
151         {
152             ValidatePlayerState(PlayerState.Playing, PlayerState.Paused);
153
154             int start = 0;
155             int current = 0;
156             NativePlayer.GetStreamingDownloadProgress(Handle, out start, out current).
157                 ThrowIfFailed("Failed to get download progress");
158
159             Log.Info(PlayerLog.Tag, "get download progress : " + start + ", " + current);
160
161             return new DownloadProgress(start, current);
162         }
163
164         /// <summary>
165         /// Sets the subtitle path for playback.
166         /// </summary>
167         /// <remarks>Only MicroDVD/SubViewer(*.sub), SAMI(*.smi), and SubRip(*.srt) subtitle formats are supported.
168         ///     <para>The mediastorage privilege(http://tizen.org/privilege/mediastorage) must be added if any files are used to play located in the internal storage.
169         ///     The externalstorage privilege(http://tizen.org/privilege/externalstorage) must be added if any files are used to play located in the external storage.</para>
170         /// </remarks>
171         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
172         /// <exception cref="ArgumentException"><paramref name="path"/> is an empty string.</exception>
173         /// <exception cref="FileNotFoundException">The specified path does not exist.</exception>
174         /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
175         /// <since_tizen> 3 </since_tizen>
176         public void SetSubtitle(string path)
177         {
178             ValidateNotDisposed();
179
180             if (path == null)
181             {
182                 throw new ArgumentNullException(nameof(path));
183             }
184
185             if (path.Length == 0)
186             {
187                 throw new ArgumentException("The path is empty.", nameof(path));
188             }
189
190             if (!File.Exists(path))
191             {
192                 throw new FileNotFoundException($"The specified file does not exist.", path);
193             }
194
195             NativePlayer.SetSubtitlePath(Handle, path).
196                 ThrowIfFailed("Failed to set the subtitle path to the player");
197         }
198
199         /// <summary>
200         /// Removes the subtitle path.
201         /// </summary>
202         /// <remarks>The player must be in the <see cref="PlayerState.Idle"/> state.</remarks>
203         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
204         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
205         /// <since_tizen> 3 </since_tizen>
206         public void ClearSubtitle()
207         {
208             ValidatePlayerState(PlayerState.Idle);
209
210             NativePlayer.SetSubtitlePath(Handle, null).
211                 ThrowIfFailed("Failed to clear the subtitle of the player");
212         }
213
214         /// <summary>
215         /// Sets the offset for the subtitle.
216         /// </summary>
217         /// <param name="offset">The value indicating a desired offset in milliseconds.</param>
218         /// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
219         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
220         /// <exception cref="InvalidOperationException">
221         ///     The player is not in the valid state.<br/>
222         ///     -or-<br/>
223         ///     No subtitle is set.
224         /// </exception>
225         /// <seealso cref="SetSubtitle(string)"/>
226         /// <since_tizen> 3 </since_tizen>
227         public void SetSubtitleOffset(int offset)
228         {
229             ValidatePlayerState(PlayerState.Playing, PlayerState.Paused);
230
231             var err = NativePlayer.SetSubtitlePositionOffset(Handle, offset);
232
233             if (err == PlayerErrorCode.FeatureNotSupported)
234             {
235                 throw new InvalidOperationException("No subtitle set");
236             }
237
238             err.ThrowIfFailed("Failed to the subtitle offset of the player");
239         }
240
241         private void Prepare()
242         {
243             NativePlayer.Prepare(Handle).ThrowIfFailed("Failed to prepare the player");
244         }
245
246         /// <summary>
247         /// Called when the <see cref="Prepare"/> is invoked.
248         /// </summary>
249         /// <since_tizen> 3 </since_tizen>
250         protected virtual void OnPreparing()
251         {
252             RegisterEvents();
253         }
254
255         /// <summary>
256         /// Prepares the media player for playback, asynchronously.
257         /// </summary>
258         /// <returns>A task that represents the asynchronous prepare operation.</returns>
259         /// <remarks>To prepare the player, the player must be in the <see cref="PlayerState.Idle"/> state,
260         ///     and a source must be set.</remarks>
261         /// <exception cref="InvalidOperationException">No source is set.</exception>
262         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
263         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
264         /// <since_tizen> 3 </since_tizen>
265         public virtual Task PrepareAsync()
266         {
267             if (_source == null)
268             {
269                 throw new InvalidOperationException("No source is set.");
270             }
271
272             ValidatePlayerState(PlayerState.Idle);
273
274             OnPreparing();
275
276             var completionSource = new TaskCompletionSource<bool>();
277
278             SetPreparing();
279
280             Task.Run(() =>
281             {
282                 try
283                 {
284                     Prepare();
285                     ClearPreparing();
286                     completionSource.SetResult(true);
287                 }
288                 catch (Exception e)
289                 {
290                     ClearPreparing();
291                     completionSource.TrySetException(e);
292                 }
293             });
294
295             return completionSource.Task;
296         }
297
298         /// <summary>
299         /// Unprepares the player.
300         /// </summary>
301         /// <remarks>
302         ///     The most recently used source is reset and is no longer associated with the player. Playback is no longer possible.
303         ///     If you want to use the player again, you have to set a source and call <see cref="PrepareAsync"/> again.
304         ///     <para>
305         ///     The player must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/>, or <see cref="PlayerState.Paused"/> state.
306         ///     It has no effect if the player is already in the <see cref="PlayerState.Idle"/> state.
307         ///     </para>
308         /// </remarks>
309         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
310         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
311         /// <since_tizen> 3 </since_tizen>
312         public virtual void Unprepare()
313         {
314             if (State == PlayerState.Idle)
315             {
316                 Log.Warn(PlayerLog.Tag, "idle state already");
317                 return;
318             }
319             ValidatePlayerState(PlayerState.Ready, PlayerState.Paused, PlayerState.Playing);
320
321             NativePlayer.Unprepare(Handle).ThrowIfFailed("Failed to unprepare the player");
322
323             OnUnprepared();
324         }
325
326         /// <summary>
327         /// Called after the <see cref="Player"/> is unprepared.
328         /// </summary>
329         /// <seealso cref="Unprepare"/>
330         /// <since_tizen> 3 </since_tizen>
331         protected virtual void OnUnprepared()
332         {
333             _source?.DetachFrom(this);
334             _source = null;
335         }
336
337         /// <summary>
338         /// Starts or resumes playback.
339         /// </summary>
340         /// <remarks>
341         /// The player must be in the <see cref="PlayerState.Ready"/> or <see cref="PlayerState.Paused"/> state.
342         /// It has no effect if the player is already in the <see cref="PlayerState.Playing"/> state.<br/>
343         /// <br/>
344         /// Sound can be mixed with other sounds if you don't control the stream focus using <see cref="ApplyAudioStreamPolicy"/>.
345         /// </remarks>
346         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
347         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
348         /// <seealso cref="PrepareAsync"/>
349         /// <seealso cref="Stop"/>
350         /// <seealso cref="Pause"/>
351         /// <seealso cref="PlaybackCompleted"/>
352         /// <seealso cref="ApplyAudioStreamPolicy"/>
353         /// <since_tizen> 3 </since_tizen>
354         public virtual void Start()
355         {
356             if (State == PlayerState.Playing)
357             {
358                 Log.Warn(PlayerLog.Tag, "playing state already");
359                 return;
360             }
361             ValidatePlayerState(PlayerState.Ready, PlayerState.Paused);
362
363             NativePlayer.Start(Handle).ThrowIfFailed("Failed to start the player");
364         }
365
366         /// <summary>
367         /// Stops playing the media content.
368         /// </summary>
369         /// <remarks>
370         /// The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.
371         /// It has no effect if the player is already in the <see cref="PlayerState.Ready"/> state.
372         /// </remarks>
373         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
374         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
375         /// <seealso cref="Start"/>
376         /// <seealso cref="Pause"/>
377         /// <since_tizen> 3 </since_tizen>
378         public virtual void Stop()
379         {
380             if (State == PlayerState.Ready)
381             {
382                 Log.Warn(PlayerLog.Tag, "ready state already");
383                 return;
384             }
385             ValidatePlayerState(PlayerState.Paused, PlayerState.Playing);
386
387             NativePlayer.Stop(Handle).ThrowIfFailed("Failed to stop the player");
388         }
389
390         /// <summary>
391         /// Pauses the player.
392         /// </summary>
393         /// <remarks>
394         /// The player must be in the <see cref="PlayerState.Playing"/> state.
395         /// It has no effect if the player is already in the <see cref="PlayerState.Paused"/> state.
396         /// </remarks>
397         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
398         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
399         /// <seealso cref="Start"/>
400         /// <since_tizen> 3 </since_tizen>
401         public virtual void Pause()
402         {
403             if (State == PlayerState.Paused)
404             {
405                 Log.Warn(PlayerLog.Tag, "pause state already");
406                 return;
407             }
408
409             ValidatePlayerState(PlayerState.Playing);
410
411             NativePlayer.Pause(Handle).ThrowIfFailed("Failed to pause the player");
412         }
413
414         private MediaSource _source;
415
416         /// <summary>
417         /// Sets a media source for the player.
418         /// </summary>
419         /// <param name="source">A <see cref="MediaSource"/> that specifies the source for playback.</param>
420         /// <remarks>The player must be in the <see cref="PlayerState.Idle"/> state.</remarks>
421         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
422         /// <exception cref="InvalidOperationException">
423         ///     The player is not in the valid state.<br/>
424         ///     -or-<br/>
425         ///     It is not able to assign the source to the player.
426         ///     </exception>
427         /// <seealso cref="PrepareAsync"/>
428         /// <since_tizen> 3 </since_tizen>
429         public void SetSource(MediaSource source)
430         {
431             ValidatePlayerState(PlayerState.Idle);
432
433             if (source != null)
434             {
435                 source.AttachTo(this);
436             }
437
438             if (_source != null)
439             {
440                 _source.DetachFrom(this);
441             }
442
443             _source = source;
444         }
445
446         /// <summary>
447         /// Captures a video frame, asynchronously.
448         /// </summary>
449         /// <returns>A task that represents the asynchronous capture operation.</returns>
450         /// <feature>http://tizen.org/feature/multimedia.raw_video</feature>
451         /// <remarks>The player must be in the <see cref="PlayerState.Playing"/> or <see cref="PlayerState.Paused"/> state.</remarks>
452         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
453         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
454         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
455         /// <since_tizen> 3 </since_tizen>
456         public async Task<CapturedFrame> CaptureVideoAsync()
457         {
458             ValidationUtil.ValidateFeatureSupported(Features.RawVideo);
459
460             ValidatePlayerState(PlayerState.Playing, PlayerState.Paused);
461
462             TaskCompletionSource<CapturedFrame> t = new TaskCompletionSource<CapturedFrame>();
463
464             NativePlayer.VideoCaptureCallback cb = (data, width, height, size, _) =>
465             {
466                 Debug.Assert(size <= int.MaxValue);
467
468                 byte[] buf = new byte[size];
469                 Marshal.Copy(data, buf, 0, (int)size);
470
471                 t.TrySetResult(new CapturedFrame(buf, width, height));
472             };
473
474             using (var cbKeeper = ObjectKeeper.Get(cb))
475             {
476                 NativePlayer.CaptureVideo(Handle, cb)
477                     .ThrowIfFailed("Failed to capture the video");
478
479                 return await t.Task;
480             }
481         }
482
483         /// <summary>
484         /// Gets the play position in milliseconds.
485         /// </summary>
486         /// <remarks>The player must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/>,
487         /// or <see cref="PlayerState.Paused"/> state.</remarks>
488         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
489         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
490         /// <seealso cref="SetPlayPositionAsync(int, bool)"/>
491         /// <since_tizen> 3 </since_tizen>
492         public int GetPlayPosition()
493         {
494             ValidatePlayerState(PlayerState.Ready, PlayerState.Paused, PlayerState.Playing);
495
496             int playPosition = 0;
497
498             NativePlayer.GetPlayPosition(Handle, out playPosition).
499                 ThrowIfFailed("Failed to get the play position of the player");
500
501             Log.Info(PlayerLog.Tag, "get play position : " + playPosition);
502
503             return playPosition;
504         }
505
506         private void SetPlayPosition(int milliseconds, bool accurate,
507             NativePlayer.SeekCompletedCallback cb)
508         {
509             var ret = NativePlayer.SetPlayPosition(Handle, milliseconds, accurate, cb, IntPtr.Zero);
510
511             //Note that we assume invalid param error is returned only when the position value is invalid.
512             if (ret == PlayerErrorCode.InvalidArgument)
513             {
514                 throw new ArgumentOutOfRangeException(nameof(milliseconds), milliseconds,
515                     "The position is not valid.");
516             }
517             if (ret != PlayerErrorCode.None)
518             {
519                 Log.Error(PlayerLog.Tag, "Failed to set play position, " + (PlayerError)ret);
520             }
521             ret.ThrowIfFailed("Failed to set play position");
522         }
523
524         /// <summary>
525         /// Sets the seek position for playback, asynchronously.
526         /// </summary>
527         /// <param name="position">The value indicating a desired position in milliseconds.</param>
528         /// <param name="accurate">The value indicating whether the operation performs with accuracy.</param>
529         /// <remarks>
530         ///     <para>The player must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/>,
531         ///     or <see cref="PlayerState.Paused"/> state.</para>
532         ///     <para>If the <paramref name="accurate"/> is true, the play position will be adjusted as the specified <paramref name="position"/> value,
533         ///     but this might be considerably slow. If false, the play position will be a nearest keyframe position.</para>
534         ///     </remarks>
535         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
536         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
537         /// <exception cref="ArgumentOutOfRangeException">The specified position is not valid.</exception>
538         /// <seealso cref="GetPlayPosition"/>
539         /// <since_tizen> 3 </since_tizen>
540         public async Task SetPlayPositionAsync(int position, bool accurate)
541         {
542             ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
543
544             var taskCompletionSource = new TaskCompletionSource<bool>(TaskCreationOptions.RunContinuationsAsynchronously);
545
546             bool immediateResult = _source is MediaStreamSource;
547
548             NativePlayer.SeekCompletedCallback cb = _ => taskCompletionSource.TrySetResult(true);
549
550             using (var cbKeeper = ObjectKeeper.Get(cb))
551             {
552                 SetPlayPosition(position, accurate, cb);
553                 if (immediateResult)
554                 {
555                     taskCompletionSource.TrySetResult(true);
556                 }
557
558                 await taskCompletionSource.Task;
559             }
560         }
561
562         /// <summary>
563         /// Sets the playback rate.
564         /// </summary>
565         /// <param name="rate">The value for the playback rate. Valid range is -5.0 to 5.0, inclusive.</param>
566         /// <remarks>
567         ///     <para>The player must be in the <see cref="PlayerState.Ready"/>, <see cref="PlayerState.Playing"/>,
568         ///     or <see cref="PlayerState.Paused"/> state.</para>
569         ///     <para>The sound will be muted, when the playback rate is under 0.0 or over 2.0.</para>
570         /// </remarks>
571         /// <exception cref="ObjectDisposedException">The player has already been disposed of.</exception>
572         /// <exception cref="InvalidOperationException">
573         ///     The player is not in the valid state.<br/>
574         ///     -or-<br/>
575         ///     Streaming playback.
576         /// </exception>
577         /// <exception cref="ArgumentOutOfRangeException">
578         ///     <paramref name="rate"/> is less than 5.0.<br/>
579         ///     -or-<br/>
580         ///     <paramref name="rate"/> is greater than 5.0.<br/>
581         ///     -or-<br/>
582         ///     <paramref name="rate"/> is zero.
583         /// </exception>
584         /// <since_tizen> 3 </since_tizen>
585         public void SetPlaybackRate(float rate)
586         {
587             if (rate < -5.0F || 5.0F < rate || rate == 0.0F)
588             {
589                 throw new ArgumentOutOfRangeException(nameof(rate), rate, "Valid range is -5.0 to 5.0 (except 0.0)");
590             }
591
592             ValidatePlayerState(PlayerState.Ready, PlayerState.Playing, PlayerState.Paused);
593
594             NativePlayer.SetPlaybackRate(Handle, rate).ThrowIfFailed("Failed to set the playback rate.");
595         }
596
597         /// <summary>
598         /// Applies the audio stream policy.
599         /// </summary>
600         /// <param name="policy">The <see cref="AudioStreamPolicy"/> to apply.</param>
601         /// <remarks>
602         /// The player must be in the <see cref="PlayerState.Idle"/> state.<br/>
603         /// <br/>
604         /// <see cref="Player"/> does not support all <see cref="AudioStreamType"/>.<br/>
605         /// Supported types are <see cref="AudioStreamType.Media"/>, <see cref="AudioStreamType.System"/>,
606         /// <see cref="AudioStreamType.Alarm"/>, <see cref="AudioStreamType.Notification"/>,
607         /// <see cref="AudioStreamType.Emergency"/>, <see cref="AudioStreamType.VoiceInformation"/>,
608         /// <see cref="AudioStreamType.RingtoneVoip"/> and <see cref="AudioStreamType.MediaExternalOnly"/>.
609         /// </remarks>
610         /// <exception cref="ObjectDisposedException">
611         ///     The player has already been disposed of.<br/>
612         ///     -or-<br/>
613         ///     <paramref name="policy"/> has already been disposed of.
614         /// </exception>
615         /// <exception cref="InvalidOperationException">The player is not in the valid state.</exception>
616         /// <exception cref="ArgumentNullException"><paramref name="policy"/> is null.</exception>
617         /// <exception cref="NotSupportedException">
618         ///     <see cref="AudioStreamType"/> of <paramref name="policy"/> is not supported by <see cref="Player"/>.
619         /// </exception>
620         /// <seealso cref="AudioStreamPolicy"/>
621         /// <since_tizen> 3 </since_tizen>
622         public void ApplyAudioStreamPolicy(AudioStreamPolicy policy)
623         {
624             if (policy == null)
625             {
626                 throw new ArgumentNullException(nameof(policy));
627             }
628
629             ValidatePlayerState(PlayerState.Idle);
630
631             NativePlayer.SetAudioPolicyInfo(Handle, policy.Handle).
632                 ThrowIfFailed("Failed to set the audio stream policy to the player");
633         }
634         #endregion
635
636         #region Preparing state
637
638         private int _isPreparing;
639
640         private bool IsPreparing()
641         {
642             return Interlocked.CompareExchange(ref _isPreparing, 1, 1) == 1;
643         }
644
645         private void SetPreparing()
646         {
647             Interlocked.Exchange(ref _isPreparing, 1);
648         }
649
650         private void ClearPreparing()
651         {
652             Interlocked.Exchange(ref _isPreparing, 0);
653         }
654
655         #endregion
656
657         /// <summary>
658         /// This method supports the product infrastructure and is not intended to be used directly from application code.
659         /// </summary>
660         /// <since_tizen> 4 </since_tizen>
661         [EditorBrowsable(EditorBrowsableState.Never)]
662         protected static Exception GetException(int errorCode, string message) =>
663             ((PlayerErrorCode)errorCode).GetException(message);
664     }
665 }