来自 HttpResponse 对象的 Android 视频流

发布于 2024-11-16 13:28:49 字数 191 浏览 3 评论 0原文

我想播放 HttpResponse 对象中的视频内容。内容正在从流媒体服务器下载。

我的要求是创建一个到服务器的 HTTP POST 请求。请求包含视频的 URL、用户的用户名和密码,用于身份验证。

我想知道如何创建 HTTP POST 请求并播放/下载视频。

请提供一些提示、步骤/代码以继续。

谢谢,

I want to play video content from HttpResponse object. The content is downloading from a streaming sever.

My requirement is to create a HTTP POST request to the server. Request contains the URL of video, username and password of the user for authentication purpose.

I wish to know how can we create a HTTP POST request and play/download the video.

Kindly provide some hints, steps/code to proceed.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉态萌生 2024-11-23 13:28:49

我不是 100% 确定,但我认为由于格式存储视频元数据的方式,您无法流式传输大部分视频。这就是为什么 youtube 必须转换视频文件而不是仅仅以任何格式显示它们。
有一些协议封装了这些元数据并允许您流式传输任何视频(这就是 youtube mobile 所做的)。您应该看一下 RTSP:http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol

如果您在 videoView 中使用 rtsp 链接,它应该可以完美地传输视频。关键是你的问题是服务器而不是客户端相关。

作为练习,您可以从 m.youtube.com 获取 rtsp 链接,然后使用 setVideoPath 传递到 videoView,它应该可以工作。

如果无法更改服务器实现,那么您可能会遇到问题,我猜您的解决方案是:

1)自己下载并解码视频,您必须处理所有元数据并确保视频正常工作。理论上,你可以为 android 编译 ffmpeg 来帮助你,但我无法在网络选项打开的情况下将其编译为 android。这是很多工作。

2) 编写您自己的 RTSP 或其他流媒体协议的实现。在线程中下载视频,然后在设备中创建本地服务器以将该视频文件流式传输到 videoView 实例。我实际上已经在一个应用程序上进行了此操作。 Android 不支持客户端服务器使用的特定协议,我必须让它工作。我花了整整一个月的时间才完成这件事。我无法发布任何示例代码,因为它都是客户的,但如果您感兴趣,我可以为您提供一些进一步的信息。

无论哪种方式,如果您无法更改视频的服务器/格式,那么您应该做好大量工作的准备。

I am not 100% sure, but I think that you can't stream most of the video due to the way the format stores the meta data of the video. That's why you tube has to convert your video files instead of just showing them in any format.
There are protocols that encapsulate this metadata and allows you to stream any video (that's what youtube mobile does). You should take a look at RTSP: http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol

If you use an rtsp link in a videoView it should stream the video flawlessly. The point is that your problem is server and not client related.

As an exercise you could grab an rtsp link from m.youtube.com and just pass to a videoView using setVideoPath and it should work.

If can't change the server implementation then you probably them I guess your solutions are:

1) Download and decode the video yourself, you would have to handle all the metadata and ensure that the video does work though. You could, theoretically, compile ffmpeg for android to help you with that, but I couldn't compile it to android with the network option on. That is a lot of work.

2) Write your own implementation of RTSP or other streaming protocol. Download the video in a thread and them create a local server in the device to stream that video file to a videoView instance. I actually have this working on an app. Android doesn't support the specific protocol that the client's servers use and I had to get it working. It took me a full month to do this. I can't post any example code because it's all the client's, but I could give you some further info on this if you are interested.

Either way, if you can't change the server/format of the video then you should prepare for a whole lot of work.

雨夜星沙 2024-11-23 13:28:49

检查以下代码以在视频视图中显示 url http 或 rtsp。

现在,在调用您的videoview之前..只需获取

public class VideoViewDemo extends Activity {

    /**
     * TODO: Set the path variable to a streaming video URL or a local media
     * file path.
     */
    private String path = "";
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.videoview);
        mVideoView = (VideoView) findViewById(R.id.surface_view);

        if (path == "") {
            // Tell the user to provide a media file URL/path.
            Toast.makeText(
                    VideoViewDemo.this,
                    "Please edit VideoViewDemo Activity, and set path"
                            + " variable to your media file URL/path",
                    Toast.LENGTH_LONG).show();

        } else {

            /*
             * Alternatively,for streaming media you can use
             * mVideoView.setVideoURI(Uri.parse(URLstring));
             */
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(this));
            mVideoView.requestFocus();

        }
    }
}

Now,因为您的要求不同,首先向您的服务器发出http post请求...获取所需的输入流..将该流作为mp4写入本地文件系统。然后你可以使用下面的代码来播放内容

// this can be path on file system
 String path="/adf.mp4"  ; 
    public void playVideo() { 

        MediaController mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        videoView.setVideoPath(path);   
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        videoView.start();
        mediaController.show();

check the below code for showing a url http or rtsp in Video View.

Now before invoking your videoview .. just get

public class VideoViewDemo extends Activity {

    /**
     * TODO: Set the path variable to a streaming video URL or a local media
     * file path.
     */
    private String path = "";
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.videoview);
        mVideoView = (VideoView) findViewById(R.id.surface_view);

        if (path == "") {
            // Tell the user to provide a media file URL/path.
            Toast.makeText(
                    VideoViewDemo.this,
                    "Please edit VideoViewDemo Activity, and set path"
                            + " variable to your media file URL/path",
                    Toast.LENGTH_LONG).show();

        } else {

            /*
             * Alternatively,for streaming media you can use
             * mVideoView.setVideoURI(Uri.parse(URLstring));
             */
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(this));
            mVideoView.requestFocus();

        }
    }
}

Now since your requirements are different first make http post request to your server ... get the desired input stream.. write that stream as mp4 to your local file system. then you can use below code to play content

// this can be path on file system
 String path="/adf.mp4"  ; 
    public void playVideo() { 

        MediaController mediaController = new MediaController(this);
        mediaController.setMediaPlayer(videoView);
        videoView.setVideoPath(path);   
        videoView.setMediaController(mediaController);
        videoView.requestFocus();
        videoView.start();
        mediaController.show();
弥繁 2024-11-23 13:28:49

我尝试了这个,它对我有用:D 没有 rtsp 没有什么,只是一个带有 mp4 视频的 url,它就播放了!

public class VideoActivity extends Activity {
    public static final String KEY = "video_id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fotogaleria_video);
    Intent i = getIntent();
    if(i.hasExtra(KEY)){
        String url = "https://sites.google.com/site/tempmp4download/bnm.mp4";
        VideoView vv = (VideoView)findViewById(R.id.fotogaleria_video);
        // vv.setVideoPath(url);
        vv.setVideoURI(Uri.parse(url));
        vv.setMediaController(new MediaController(this));
        vv.requestFocus();
        vv.start();

        }

    }
}

I tried this and it worked for me :D no rtsp no nothing, just a url with a mp4 video and it played!

public class VideoActivity extends Activity {
    public static final String KEY = "video_id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fotogaleria_video);
    Intent i = getIntent();
    if(i.hasExtra(KEY)){
        String url = "https://sites.google.com/site/tempmp4download/bnm.mp4";
        VideoView vv = (VideoView)findViewById(R.id.fotogaleria_video);
        // vv.setVideoPath(url);
        vv.setVideoURI(Uri.parse(url));
        vv.setMediaController(new MediaController(this));
        vv.requestFocus();
        vv.start();

        }

    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文