[AudioManager] Add HasStreamOnDevice method to AudioStreamPolicy (#711)
authorSangchul Lee <sangchul1011@gmail.com>
Wed, 20 Feb 2019 01:43:32 +0000 (10:43 +0900)
committerGitHub <noreply@github.com>
Wed, 20 Feb 2019 01:43:32 +0000 (10:43 +0900)
* [AudioManager] Add IsStreamOnDevice method to AudioStreamPolicy

* [AudioManager] Rename IsStreamOnDevice to HasStreamOnDevice

* [AudioManager] Add more explanation for HasStreamOnDevice method

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
src/Tizen.Multimedia/AudioManager/AudioStreamPolicy.cs
src/Tizen.Multimedia/Interop/Interop.StreamPolicy.cs

index d661c75..0309e92 100644 (file)
@@ -305,6 +305,37 @@ namespace Tizen.Multimedia
         }
 
         /// <summary>
+        /// Checks if any stream from the current AudioStreamPolicy is using the device.
+        /// </summary>
+        /// <returns>true if any audio stream from the current AudioStreamPolicy is using the device; otherwise, false.</returns>
+        /// <param name="device">The device to be checked.</param>
+        /// <remarks>
+        /// The AudioStreamPolicy can be applied to each playback or recording stream via other API set.
+        /// (For example., <see cref="T:Tizen.Multimedia.Player"/>, <see cref="T:Tizen.Multimedia.WavPlayer"/>,
+        /// <see cref="T:Tizen.Multimedia.AudioPlayback"/>, <see cref="T:Tizen.Multimedia.AudioCapture"/>, etc.)
+        /// This method returns true only when the device is used for the stream which meets to the two conditions.
+        /// One is that the current AudioStreamPolicy sets a audio route path to the device and the other is that the playback
+        /// or recording stream from other API set should have already started to prepare or to play.(It depends on the API set.)
+        /// </remarks>
+        /// <exception cref="ArgumentNullException"><paramref name="device"/> is null.</exception>
+        /// <exception cref="InvalidOperationException">An internal error occurs.</exception>
+        /// <exception cref="ObjectDisposedException">The <see cref="AudioStreamPolicy"/> has already been disposed of.</exception>
+        /// <seealso cref="AudioManager.GetConnectedDevices()"/>
+        /// <since_tizen> 6 </since_tizen>
+        public bool HasStreamOnDevice(AudioDevice device)
+        {
+            if (device == null)
+            {
+                throw new ArgumentNullException(nameof(device));
+            }
+
+            var ret = Interop.AudioStreamPolicy.IsStreamOnDevice(Handle, device.Id, out var isOn);
+            ret.ThrowIfError("Failed to check stream on device");
+
+            return isOn;
+        }
+
+        /// <summary>
         /// Releases all resources used by the <see cref="AudioStreamPolicy"/>.
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
index 0ab53a2..5c0dc0a 100644 (file)
@@ -81,6 +81,10 @@ namespace Tizen.Multimedia
 
             [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_remove_focus_state_watch_cb")]
             internal static extern int RemoveFocusStateWatchCallback(int id);
+
+            [DllImport(Libraries.SoundManager, EntryPoint = "sound_manager_is_stream_on_device_by_id")]
+            internal static extern AudioManagerError IsStreamOnDevice(AudioStreamPolicyHandle streamInfo, int deviceId,
+                out bool isOn);
         }
     }
 }
\ No newline at end of file