0

我使用以下代码从 mjpg-streamer 加载视频:

    Uri uri = Uri.parse("my server url");
    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(intent);

这仅在我使用 Opera 浏览器打开远程 url 时才有效。现在我想在手机上播放相同的视频:

Uri uri = Uri.parse("url");
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("http://url/?action=stream"), "multipart/x-   mixed-replace;boundary=boundarydonotcross"); 
startActivity(intent);

我面临以下问题:

07-24 10:34:13.750: E/AndroidRuntime(27778): FATAL EXCEPTION: main
07-24 10:34:13.750: E/AndroidRuntime(27778): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.media/com.example.media.MainActivity}: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://xxxxxxx.xxx/ typ=multipart/x-mixed-replace;boundary=boundarydonotcross }
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.os.Looper.loop(Looper.java:130)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread.main(ActivityThread.java:3687)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at java.lang.reflect.Method.invokeNative(Native Method)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at java.lang.reflect.Method.invoke(Method.java:507)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at dalvik.system.NativeStart.main(Native Method)
07-24 10:34:13.750: E/AndroidRuntime(27778): Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://xxxxxxx.xxx/ typ=multipart/x-mixed-replace;boundary=boundarydonotcross }
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.Activity.startActivityForResult(Activity.java:2827)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.Activity.startActivity(Activity.java:2933)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at com.example.media.MainActivity.onCreate(MainActivity.java:26)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-24 10:34:13.750: E/AndroidRuntime(27778):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
07-24 10:34:13.750: E/AndroidRuntime(27778):    ... 11 more

我也尝试过使用MediaPLayer.create(this,myuri),但它一直告诉我无法在客户端打开文件。

4

1 回答 1

0

您可以使用 VideoView 播放视频

VideoView video=(VideoView) findViewById(R.id.videoview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video);
video.setMediaController(mediaController);

video.setVideoURI(Uri.parse(path));
video.start();
video.requestFocus();
于 2012-07-24T05:19:44.660 回答