[Android] [PATCH] Add open MRL feature in menu

Edward Wang edward.c.wang at compdigitec.com
Sun Mar 11 06:29:18 CET 2012


---
Sorry, there was an error in the previous patch that caused VLC to crash.
This update fixes it to ensure that no crash will occur.

 vlc-android/res/menu/media_library.xml             |    4 +++
 vlc-android/res/values/strings.xml                 |    1 +
 vlc-android/src/org/videolan/vlc/AudioService.java |    5 +++
 .../src/org/videolan/vlc/gui/MainActivity.java     |   27 ++++++++++++++++++++
 4 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/vlc-android/res/menu/media_library.xml b/vlc-android/res/menu/media_library.xml
index 06c0166..729f843 100644
--- a/vlc-android/res/menu/media_library.xml
+++ b/vlc-android/res/menu/media_library.xml
@@ -25,4 +25,8 @@
         android:id="@+id/ml_menu_refresh"
         android:icon="@drawable/ic_menu_refresh"
         android:title="@string/refresh" />
+    <item
+        android:id="@+id/ml_menu_open_mrl"
+        android:icon="@android:drawable/ic_btn_speak_now"
+        android:title="@string/open_mrl" />
 </menu>
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 541132b..28c78d3 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -78,4 +78,5 @@
     <string name="track_video_info">Codec: %1$s\nResolution: %2$dx%3$d</string>
     <string name="track_text">Subtitles track</string>
     <string name="track_unknown">Unknown track</string>
+    <string name="open_mrl">Open MRL</string>
 </resources>
diff --git a/vlc-android/src/org/videolan/vlc/AudioService.java b/vlc-android/src/org/videolan/vlc/AudioService.java
index f35aa8d..5d0f40a 100644
--- a/vlc-android/src/org/videolan/vlc/AudioService.java
+++ b/vlc-android/src/org/videolan/vlc/AudioService.java
@@ -463,6 +463,7 @@ public class AudioService extends Service {
         @Override
         public void load(List<String> mediaPathList, int position)
                 throws RemoteException {
+            Log.v(TAG, "Loading position " + ((Integer)position).toString() + " in " + mediaPathList.toString());
             mEventManager.addHandler(mEventHandler);
             mMediaList.clear();
             mPrevious.clear();
@@ -470,6 +471,10 @@ public class AudioService extends Service {
             for (int i = 0; i < mediaPathList.size(); i++) {
                 String path = mediaPathList.get(i);
                 Media media = db.getMedia(AudioService.this, path);
+                if(media == null) {
+                    Log.v(TAG, "Creating on-the-fly Media object for " + path);
+                    media = new Media(AudioService.this, path, false);
+                }
                 mMediaList.add(media);
             }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 2660948..3868d41 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -20,6 +20,8 @@
 
 package org.videolan.vlc.gui;
 
+import java.util.ArrayList;
+
 import org.videolan.vlc.AudioServiceController;
 import org.videolan.vlc.LibVLC;
 import org.videolan.vlc.MediaLibrary;
@@ -33,10 +35,12 @@ import org.videolan.vlc.widget.AudioMiniPlayer;
 
 import android.app.Activity;
 import android.app.ActivityGroup;
+import android.app.AlertDialog;
 import android.app.Dialog;
 import android.app.TabActivity;
 import android.content.BroadcastReceiver;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.SharedPreferences;
@@ -53,6 +57,7 @@ import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.Button;
 import android.widget.CheckBox;
+import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.ProgressBar;
 import android.widget.TabHost;
@@ -232,6 +237,28 @@ public class MainActivity extends TabActivity {
             case R.id.ml_menu_refresh:
                 MediaLibrary.getInstance(this).loadMediaItems(this);
                 break;
+            case R.id.ml_menu_open_mrl:
+                AlertDialog.Builder b = new AlertDialog.Builder(this);
+                final EditText input = new EditText(this);
+                b.setTitle("Resource MRL");
+                b.setMessage("Enter MRL (media resource locator): e.g. rtsp:// or http://");
+                b.setView(input);
+                b.setPositiveButton("Open", new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int button) {
+                        AudioServiceController c = AudioServiceController.getInstance();
+                        ArrayList<String> media = new ArrayList<String>();
+                        media.add(input.getText().toString());
+                        c.append(media);
+                        }
+                    }
+                );
+                b.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+                    @Override
+                    public void onClick(DialogInterface arg0, int arg1) {
+                        return;
+                        }});
+                b.show();
+                break;
         }
         return super.onOptionsItemSelected(item);
     }
-- 
1.7.5.4



More information about the Android mailing list