OSDN Git Service

Fix Issue 5547: Apollo will not play MP3 files when using Root Explorer
[android-x86/packages-apps-Eleven.git] / src / com / andrew / apollo / service / ApolloService.java
index bbccfcd..b521ab3 100644 (file)
@@ -1130,10 +1130,16 @@ public class ApolloService extends Service {
                     where = null;\r
                     selectionArgs = null;\r
                 } else {\r
+                    // Remove schema for search in the database\r
+                    // Otherwise the file will not found\r
+                    String data = path;\r
+                    if( data.startsWith("file://") ){\r
+                        data = data.substring(7);\r
+                    }\r
                     uri = MediaStore.Audio.Media.getContentUriForPath(path);\r
                     where = MediaColumns.DATA + "=?";\r
                     selectionArgs = new String[] {\r
-                        path\r
+                        data\r
                     };\r
                 }\r
 \r
@@ -1178,6 +1184,48 @@ public class ApolloService extends Service {
     }\r
 \r
     /**\r
+     * Method that query the media database for search a path an translate\r
+     * to the internal media id\r
+     *\r
+     * @param path The path to search\r
+     * @return long The id of the resource, or -1 if not found\r
+     */\r
+    public long getIdFromPath(String path) {\r
+        try {\r
+            // Remove schema for search in the database\r
+            // Otherwise the file will not found\r
+            String data = path;\r
+            if( data.startsWith("file://") ){\r
+                data = data.substring(7);\r
+            }\r
+            ContentResolver resolver = getContentResolver();\r
+            String where = MediaColumns.DATA + "=?";\r
+            String selectionArgs[] = new String[] {\r
+                data\r
+            };\r
+            Cursor cursor =\r
+                    resolver.query(\r
+                            MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,\r
+                            mCursorCols, where, selectionArgs, null);\r
+            try {\r
+                if (cursor == null || cursor.getCount() == 0) {\r
+                    return -1;\r
+                }\r
+                cursor.moveToNext();\r
+                return cursor.getLong(IDCOLIDX);\r
+            } finally {\r
+                try {\r
+                    if( cursor != null )\r
+                        cursor.close();\r
+                } catch (Exception ex) {\r
+                }\r
+            }\r
+        } catch (UnsupportedOperationException ex) {\r
+        }\r
+        return -1;\r
+    }\r
+\r
+    /**\r
      * Starts playback of a previously opened file.\r
      */\r
     public void play() {\r
@@ -1801,7 +1849,7 @@ public class ApolloService extends Service {
     public String getArtistName() {\r
         synchronized (this) {\r
             if (mCursor == null) {\r
-                return null;\r
+                return getString(R.string.unknown);\r
             }\r
             return mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ARTIST));\r
         }\r
@@ -1819,7 +1867,7 @@ public class ApolloService extends Service {
     public String getAlbumName() {\r
         synchronized (this) {\r
             if (mCursor == null) {\r
-                return null;\r
+                return getString(R.string.unknown);\r
             }\r
             return mCursor.getString(mCursor.getColumnIndexOrThrow(AudioColumns.ALBUM));\r
         }\r
@@ -1837,7 +1885,7 @@ public class ApolloService extends Service {
     public String getTrackName() {\r
         synchronized (this) {\r
             if (mCursor == null) {\r
-                return null;\r
+                return getString(R.string.unknown);\r
             }\r
             return mCursor.getString(mCursor.getColumnIndexOrThrow(MediaColumns.TITLE));\r
         }\r
@@ -2117,6 +2165,11 @@ public class ApolloService extends Service {
         }\r
 \r
         @Override\r
+        public long getIdFromPath(String path) {\r
+            return mService.get().getIdFromPath(path);\r
+        }\r
+\r
+        @Override\r
         public int getQueuePosition() {\r
             return mService.get().getQueuePosition();\r
         }\r