AndroidVideoMedia: Error opening

2019-11-01  本文已影响0人  贼噶人

解决办法是在App内搭建个微型的http服务器(NanoHTTPD)然后通过该本地的微型服务器访问本地视频文件来达到播放的效果

package com.jove.demo;

import android.app.Application;

import java.io.FileInputStream;

import fi.iki.elonen.NanoHTTPD;

public class VideoServer extends NanoHTTPD {

    Application application;

    public VideoServer(Application application, int port) {
        super(port);
        this.application = application;
    }

    @Override
    public Response serve(IHTTPSession session) {
        try {
            final FileInputStream inputStream = new FileInputStream(session.getUri());
            return newFixedLengthResponse(Response.Status.OK, "video/mp4", inputStream,
                    inputStream.available());
        } catch (Exception e) {
            StringBuilder builder = new StringBuilder();
            builder.append("<!DOCTYPE html><html><body>");
            builder.append("Sorry, Can't Found the page!");
            builder.append("</body></html>\n");
            return newFixedLengthResponse(Response.Status.NOT_FOUND, "text/html", builder
                    .toString());
        }
    }
}



邮箱[635901979@qq.com]

上一篇 下一篇

猜你喜欢

热点阅读