我试图在nanohttpd的帮助下使用videoView播放加密视频。但是它不工作不知道为什么?

时间:2016-05-26 13:29:15

标签: android nanohttpd

我认为问题在答案部分,但没有弄清楚在哪里可以看。

播放视频时出错:

  

D / MediaPlayer:无法在客户端打开文件,尝试服务器端
  MediaPlayer:错误(1,-2147483648)

     

E / MediaPlayer:错误(1,-2147483648)

     

目标sdk 23

     

min sdk 15

     

测试设备= api 19 kitkat

的AndroidManifest.xml:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>

MainActivity.java

super.onCreate(savedInstanceState);         的setContentView(R.layout.activity_main);

    videoView = (VideoView) findViewById(R.id.videoview);

    Log.i(TAG,String.valueOf(Environment.getExternalStorageDirectory()));


    videoHttpServer = new VideoHttpServer();


    try{

        videoHttpServer.start();


    }catch (Exception exception){

        Log.i(TAG,String.valueOf(exception.getMessage()));

    }


    File file = new File("/sdcard/a1.mp4");
    Log.i(TAG,String.valueOf(file.exists()));

    Uri uri = Uri.parse("http://127.0.0.1:8089/a1.mp4");
    videoView.setVideoURI(uri);

    videoView.setMediaController(new MediaController(MainActivity.this));

    videoView.start();

}

public class VideoHttpServer extends NanoHTTPD {

    public VideoHttpServer() {
        super(8089);


    }

    @Override
    public Response serve(String uri, Method method,
                          Map<String, String> header, Map<String, String> parameters,
                          Map<String, String> files) {
        String answer = "";

        FileInputStream fis = null;

        try {


            File file = new File("/sdcard/a1.mp4");

            fis = new FileInputStream(file);

             abc = new File(Environment.getExternalStorageDirectory()+"a1.mp4");



        } catch (Exception e) {
            // TODO Auto-generated catch block
            Log.i(TAG,String.valueOf(e.getMessage()));
        }
        return new NanoHTTPD.Response(Response.Status.OK, "video/mp4", fis,1);
    }
}

}

1 个答案:

答案 0 :(得分:0)

NanoHttpd(Java中的一个小型Web服务器)应该在服务器端使用 - 查看README.md here