[banshee] PlayerEngineService: Check DbConnection before searching for opened URI



commit 8050abfbae94da8088127c2fa28850ee83695441
Author: Bertrand Lorentz <bertrand lorentz gmail com>
Date:   Tue Aug 23 21:52:23 2011 +0200

    PlayerEngineService: Check DbConnection before searching for opened URI
    
    Using PlayerEngineService.Open (SafeUri uri) without a database would
    cause an NRE. Check that we have a DbConnection instance before trying
    to find the URI in the database.
    
    This was apparently only triggered by unit tests, but might also happen
    in some other situation.

 .../Banshee.MediaEngine/PlayerEngineService.cs     |   19 +++++++++++++------
 1 files changed, 13 insertions(+), 6 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs b/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
index cc6c70d..31d8308 100644
--- a/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
+++ b/src/Core/Banshee.Services/Banshee.MediaEngine/PlayerEngineService.cs
@@ -288,12 +288,19 @@ namespace Banshee.MediaEngine
             if (uri == null || !File.Exists (uri.AbsolutePath)) {
                 return;
             }
-            // Try to find uri in the library
-            int track_id = DatabaseTrackInfo.GetTrackIdForUri (uri);
-            if (track_id > 0) {
-                DatabaseTrackInfo track_db = DatabaseTrackInfo.Provider.FetchSingle (track_id);
-                Open (track_db);
-            } else {
+
+            bool found = false;
+            if (ServiceManager.DbConnection != null) {
+                // Try to find uri in the library
+                int track_id = DatabaseTrackInfo.GetTrackIdForUri (uri);
+                if (track_id > 0) {
+                    DatabaseTrackInfo track_db = DatabaseTrackInfo.Provider.FetchSingle (track_id);
+                    found = true;
+                    Open (track_db);
+                }
+            }
+            
+            if (!found) {
                 // Not in the library, get info from the file
                 TrackInfo track = new TrackInfo ();
                 using (var file = StreamTagger.ProcessUri (uri)) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]