From b9617683a38ba57b48e43820b97749d9e7306c83 Mon Sep 17 00:00:00 2001
From: sebastiii <sebastiii@team-mediaportal.com>
Date: Sat, 30 Mar 2013 22:49:23 +0100
Subject: [PATCH] Release AudioRenderer (Needed when using Wasapi) Add a check
 for video files when both format are added in Music and
 Video extensions.

---
 mediaportal/Core/Player/VideoPlayerVMR9.cs |  6 +++---
 mediaportal/Core/Player/g_player.cs        | 31 ++++++++++++++++++++++++++----
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/mediaportal/Core/Player/VideoPlayerVMR9.cs b/mediaportal/Core/Player/VideoPlayerVMR9.cs
index 764c7e6..b286502 100644
--- a/mediaportal/Core/Player/VideoPlayerVMR9.cs
+++ b/mediaportal/Core/Player/VideoPlayerVMR9.cs
@@ -1395,9 +1395,9 @@ namespace MediaPortal.Player
 
         if (filterCodec != null && filterCodec._audioRendererFilter != null)
         {
-          //DirectShowUtil.DisconnectAllPins(graphBuilder, filterCodec._audioRendererFilter);
-          //graphBuilder.RemoveFilter(filterCodec._audioRendererFilter);
-          //while (DirectShowUtil.ReleaseComObject(filterCodec._audioRendererFilter) > 0) ;
+          DirectShowUtil.DisconnectAllPins(graphBuilder, filterCodec._audioRendererFilter);
+          graphBuilder.RemoveFilter(filterCodec._audioRendererFilter);
+          while (DirectShowUtil.ReleaseComObject(filterCodec._audioRendererFilter) > 0) ;
           DirectShowUtil.ReleaseComObject(filterCodec._audioRendererFilter);
           filterCodec._audioRendererFilter = null;
           Log.Info("VideoPlayer9: Cleanup AudioRenderer");
diff --git a/mediaportal/Core/Player/g_player.cs b/mediaportal/Core/Player/g_player.cs
index 4c9b6ca..d9591e3 100644
--- a/mediaportal/Core/Player/g_player.cs
+++ b/mediaportal/Core/Player/g_player.cs
@@ -1285,6 +1285,12 @@ namespace MediaPortal.Player
           _mediaInfo = new MediaInfoWrapper(strFile);
         }
 
+        // Detect if the file is video
+        if (MediaInfo != null && MediaInfo.hasVideo)
+        {
+          type = MediaType.Video;
+        }
+
         if ((!playingRemoteUrl && Util.Utils.IsVideo(strFile)) || Util.Utils.IsLiveTv(strFile)) //local video, tv, rtsp
         {
           if (type == MediaType.Unknown)
@@ -1293,10 +1299,13 @@ namespace MediaPortal.Player
             type = MediaType.Video;
           }
 
-          // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
-          if (strFile.IndexOf(@"\BDMV\INDEX.BDMV") == -1)
+          if (type != MediaType.Music)
           {
-            RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType)(int)type);
+            // Refreshrate change done here. Blu-ray player will handle the refresh rate changes by itself
+            if (strFile.IndexOf(@"\BDMV\INDEX.BDMV") == -1)
+            {
+              RefreshRateChanger.AdaptRefreshRate(strFile, (RefreshRateChanger.MediaType) (int) type);
+            }
           }
 
           if (RefreshRateChanger.RefreshRateChangePending)
@@ -1335,6 +1344,10 @@ namespace MediaPortal.Player
             {
               type = MediaType.Music;
             }
+            if (MediaInfo != null && MediaInfo.hasVideo)
+            {
+              type = MediaType.Video;
+            }
             if (BassMusicPlayer.IsDefaultMusicPlayer && BassMusicPlayer.Player.Playing)
             {
               doStop = !BassMusicPlayer.Player.CrossFadingEnabled;
@@ -1351,8 +1364,18 @@ namespace MediaPortal.Player
           }
         }
 
+        if (!playingRemoteUrl && _mediaInfo == null) // MediaInfo can only be used on files (local or SMB)
+        {
+          _mediaInfo = new MediaInfoWrapper(strFile);
+        }
+
+        if (MediaInfo != null && MediaInfo.hasVideo)
+        {
+          type = MediaType.Video;
+        }
+
         Log.Info("g_Player.Play({0} {1})", strFile, type);
-        if (!playingRemoteUrl && Util.Utils.IsVideo(strFile))
+        if (!playingRemoteUrl && Util.Utils.IsVideo(strFile) && type != MediaType.Music)
         {
           if (!Util.Utils.IsRTSP(strFile) && extension != ".ts") // do not play recorded tv with external player
           {
-- 
1.8.0.msysgit.0

