Multimedia TCT : Free resources after playback
authorRavi Kiran K N <ravi.kiran@samsung.com>
Thu, 9 Jun 2016 09:09:59 +0000 (14:39 +0530)
committerRavi Kiran K N <ravi.kiran@samsung.com>
Thu, 9 Jun 2016 11:23:12 +0000 (16:53 +0530)
Add dispose function

Change-Id: I78a421b3b14a22dbdc0114f5ffbd939e71bcbcbe
Signed-off-by: Ravi Kiran K N <ravi.kiran@samsung.com>
src/Tizen.Multimedia/Player/Player.cs

index 4f0d16f115c2fa6a066b20906cdc4a63ddafa87f..1ef779325e2385e8c3ea3284e943c3e73be40c86 100755 (executable)
@@ -29,7 +29,7 @@ namespace Tizen.Multimedia
     /// of the player such as playback rate, volume, looping etc. And, event handlers
     /// handles are provided to handle various playback events (like playback error/completion)
     /// </remarks>
-    public class Player
+       public class Player : IDisposable
     {
                private EventHandler<PlaybackCompletedEventArgs> _playbackCompleted;
                private Interop.Player.PlaybackCompletedCallback _playbackCompletedCallback;
@@ -521,8 +521,33 @@ namespace Tizen.Multimedia
         /// </summary>
         ~Player()
         {
+                       Dispose(false);
         }
 
+               public void Dispose()
+               {
+                       Dispose(true);
+                       GC.SuppressFinalize(this);
+               }
+
+               protected virtual void Dispose(bool disposing)
+               {
+                       if(!_disposed)
+                       {
+                               if(disposing)
+                               {
+                                       // To be used if there are any other disposable objects
+                               }
+                               if(_playerHandle != IntPtr.Zero)
+                               {
+                                       Interop.Player.Destroy(_playerHandle);
+                                       _playerHandle = IntPtr.Zero;
+                               }
+                               _disposed = true;
+                       }
+               }
+
+
         /// <summary>
         /// Prepares the media player for playback. </summary>
                public Task<bool> PrepareAsync()
@@ -719,5 +744,6 @@ namespace Tizen.Multimedia
         internal StreamingConfiguration _streamingConfiguration;
 
                internal IntPtr _playerHandle;
+               private bool _disposed = false;
     }
 }