【问题标题】:How to show video obtained from a http request in Android and iOS?如何在 Android 和 iOS 中显示从 http 请求获得的视频?
【发布时间】:2013-05-08 09:13:08
【问题描述】:

这里我有一个网址。我无法提供整个字符串,但其中一部分是“http://*/video.mjpg”。 当我用浏览器(firefox)打开它时,它会显示视频。当我使用 Fiddler 分析包时,它显示如下:

HTTP/1.1 200 正常

服务器:*

Pragma:no-cache

缓存控制:无缓存

Content-Type:multipart/x-mixed-replace;边界=“我的边界”

我在网上搜索,我得到了这些关键词:MIME,动态解析。但我仍然不知道如何解析它。希望有人可以帮助我。如何在 Java 和 Objective-C 中解析消息以在 Android 和 iOS 中显示视频内容?

【问题讨论】:

    标签: android ios parsing httprequest multipart


    【解决方案1】:

    对于 iOS,您可以使用

    编辑

    NSString *url = @"http://*/video.mjpg";
    NSError *error = nil;
    
    videoData = [NSData dataWithContentsOfURL:[NSURL urlWithString:url] options:nil error:&error];
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:@"videoToPlay.mp4"];
    
    [videoData writeToFile:path atomically:YES];
    NSURL *moveUrl = [NSURL fileURLWithPath:path];
    player = [[MPMoviePlayerController alloc]init];
    [player setContentURL:moveUrl];
    player.view.frame = viewPlayer.bounds;
    [viewPlayer addSubview:player.view];
    [player play];
    

    看看这个来自 Apple 的 sample

    安卓版

    我不是 Android 开发人员,但我使用过这个 Answer 用于我测试的演示。

    【讨论】:

    • 我之前在iOS上试过这种方法,它显示一个全白屏。然后我尝试了您发布的Android解决方案,我的手机开始下载但无法下载任何内容。屏幕上仍然没有显示任何内容。
    • 那么你可能需要先下载整个视频然后播放它,尝试新代码,编辑我的答案。
    • 还是不行。服务器就像一种 IP 摄像机。所以它是一个连续的流。我认为不可能下载整个视频。最好从流中解析视频的每一帧。感谢您的帮助。
    【解决方案2】:

    对于安卓:

    if (the_link_of_the_video_here.startsWith("http://") == false){
    the_link_of_the_video_here="http://"+the_link_of_the_video_here;
    }
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(the_link_of_the_video_here));
    startActivity(intent);
    

    the_link_of_the_video_here 是您从 http 请求中收到的链接

    【讨论】:

    • 不起作用。该应用程序显示“开始下载”,但无法下载任何内容。屏幕什么也没显示。我的 URL 包含用户名和密码,例如“username:password@domain***”。是这个问题吗?
    • 我认为问题是视频流尝试使用 rtsp 流而不是 http 流我认为它会起作用,因为这总是发生在我身上,所以我要求客户给我 rtsp 好运: )
    猜你喜欢
    • 2017-02-01
    • 2015-03-13
    • 1970-01-01
    • 1970-01-01
    • 2014-07-17
    • 2016-02-02
    • 2012-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多