如何从远程 URL 在 Android 模拟器中显示视频?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1425502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 03:04:29  来源:igfitidea点击:

How to display Video in the Android Emulator from Remote URL?

android

提问by Rajapandian

I am using the following code to display a video file in the android emulator,it works fine when the video file is stored in a SDcard.But when i give any URL of a video the code not working.

我正在使用以下代码在 android 模拟器中显示视频文件,当视频文件存储在 SDcard 中时它工作正常。但是当我提供视频的任何 URL 时,代码不起作用。

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.View;
import android.widget.*;

public class playerActivity extends Activity 
{
Button b;
VideoView preview;
SurfaceHolder holder;
MediaPlayer mp;

 private String path = "/data/data/payoda.android/funny.mp4";

//private String path = "http://www.daily3gp.com/vids/3.3gp";

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    preview=(VideoView)findViewById(R.id.surface);
    holder=preview.getHolder();
    b=(Button)findViewById(R.id.cmd_play);
    b.setOnClickListener(new View.OnClickListener()
    {
    public void onClick(View v)
    {
        try
        {
                mp=new MediaPlayer(); 
                mp.setDataSource(path);
                mp.setScreenOnWhilePlaying(true);
                mp.setDisplay(holder);
                mp.prepare();
                mp.start();
        }
        catch(Exception e)
        {

        }
    }
    });
}
}

The Exception thorwn is:

异常 thorn 是:

prepare failed:
status=0xC8

The LogCat details are:

LogCat 详细信息是:

09-16 12:16:36.729: ERROR/PlayerDriver(542): Command PLAYER_INIT completed with an error or info PVMFErrContentInvalidForProgressivePlayback
09-16 12:16:36.739: ERROR/MediaPlayer(2867): error (200, -27)

In the above code if change the path variable the Emulator screen is black with single button.May be i have to do some more things to display the video from the Remote URL,i dont know what to do.Any one having any idea about this please help Me.

在上面的代码中,如果更改路径变量,模拟器屏幕是黑色的,只有一个按钮。可能我需要做更多的事情来显示来自远程 URL 的视频,我不知道该怎么做。任何人对此有任何想法请帮我。

回答by CommonsWare

First, do not use the emulator for testing video playback. Its ability to handle video playback is very limited. Use an actual Android device.

首先,不要使用模拟器来测试视频播放。它处理视频播放的能力非常有限。使用实际的 Android 设备。

Second, always check LogCat (adb logcat, DDMS, or DDMS perspective in Eclipse) for warnings when you run into multimedia problems. OpenCORE -- the multimedia engine used by Android -- has a tendency to log error-level conditions as warnings.

其次,adb logcat当您遇到多媒体问题时,始终检查 LogCat(Eclipse 中的 、DDMS 或 DDMS 透视图)是否有警告。OpenCORE——Android 使用的多媒体引擎——倾向于将错误级别的情况记录为警告。

For example, your video file may not be set up for progressive download, which is required for HTTP streaming. On Linux, you can patch up MP4 videos for progressive download by installing MP4Box and running MP4Box -hint <file>.

例如,您的视频文件可能没有设置为渐进式下载,这是 HTTP 流媒体所必需的。在 Linux 上,您可以通过安装 MP4Box 并运行MP4Box -hint <file>.

回答by tboyi

you should create a Sdcard in your simulator and then change your eclipse windows view to DDMS chaange your path to mnt/sdcard and push your file onto the device the action buttom is on the right-up of DDMS ,it is a phone icon

您应该在模拟器中创建一个 Sdcard,然后将您的 eclipse windows 视图更改为 DDMS 更改您到 mnt/sdcard 的路径并将您的文件推送到设备上,操作按钮位于 DDMS 的右侧,它是一个电话图标

then change your .java path

然后更改您的 .java 路径

private String path = "mnt/sdcard/funny.mp4";

your should work on it.

你应该努力。

回答by Donn Felker

You should also use the prepareAsync() method instead of prepare(). Using prepare() is a blocking call (UI gets locked), while prepareAsync is not a blocking call.

您还应该使用prepareAsync() 方法而不是 prepare()。使用 prepare() 是一个阻塞调用(UI 被锁定),而 prepareAsync 不是一个阻塞调用。