2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Diagnostics;
19 using NativeWebRTC = Interop.NativeWebRTC;
21 namespace Tizen.Multimedia.Remoting
24 /// Represents a media source with contents read from a file.
27 /// Depending on where the source file is located either the media storage privilege (http://tizen.org/privilege/mediastorage) is required or<br/>
28 /// the external storage privilege(http://tizen.org/privilege/externalstorage) is required.
30 /// <seealso cref="WebRTC.AddSource"/>
31 /// <seealso cref="WebRTC.AddSources"/>
32 /// <since_tizen> 10 </since_tizen>
33 public sealed class MediaFileSource : MediaSource
38 /// Initializes a new instance of the <see cref="MediaFileSource"/> class.
40 /// <param name="type">The <see cref="MediaType"/> of file source.</param>
41 /// <param name="path">The file path.</param>
42 /// <exception cref="ArgumentNullException"><paramref name="path"/> is null.</exception>
43 /// <since_tizen> 10 </since_tizen>
44 public MediaFileSource(MediaType type, string path) : base(type)
46 _path = path ?? throw new ArgumentNullException(nameof(path), "path is null");
50 /// Gets or sets the looping mode of the file source.
53 /// true if the transfer starts again from the beginning of the file source after reaching the end of the file; otherwise, false\n
54 /// The default value is false.
56 /// <exception cref="InvalidOperationException">MediaSource is not attached yet.</exception>
57 /// <exception cref="ObjectDisposedException">The WebRTC has already been disposed.</exception>
58 /// <since_tizen> 10 </since_tizen>
63 if (!SourceId.HasValue)
68 NativeWebRTC.GetFileSourceLooping(WebRtc.Handle, SourceId.Value, out bool isLooping).
69 ThrowIfFailed("Failed to get looping mode");
75 if (!SourceId.HasValue)
77 throw new InvalidOperationException("MediaSource is not attached yet. Call AddSource() first.");
80 NativeWebRTC.SetFileSourceLooping(WebRtc.Handle, SourceId.Value, value).
81 ThrowIfFailed("Failed to set looping mode");
85 internal override void OnAttached(WebRTC webRtc)
87 Debug.Assert(webRtc != null);
91 throw new InvalidOperationException("The source is has already been assigned to another WebRTC.");
94 NativeWebRTC.AddMediaSource(webRtc.Handle, MediaSourceType.File, out uint sourceId).
95 ThrowIfFailed("Failed to add MediaFileSource.");
97 NativeWebRTC.SetFileSourcePath(webRtc.Handle, sourceId, _path).
98 ThrowIfFailed("Failed to set path for MediaFileSource.");
104 internal override void OnDetached(WebRTC webRtc)
106 NativeWebRTC.RemoveMediaSource(webRtc.Handle, SourceId.Value).
107 ThrowIfFailed("Failed to remove MediaFileSource.");