Playback of downloaded video Error: 1, -2147483648

I am trying to upload a video file and then play it in the application, if I put the video file in the res folder, I can play it without problems, however, when I try to download the video, play it I get VideoView Error: 1, -2147483648.

This is the code I use to download the video:

    try
    {

        URL url = new URL(videoURL);
        URLConnection conexion = url.openConnection();
        conexion.connect();

        int lengthOfFile = conexion.getContentLength();
        Log.d("ANDRO_ASYNC", "Length of file: " + lengthOfFile);

        InputStream input = new BufferedInputStream(url.openStream());




        final File dir = new File(this.getFilesDir() + "/videos");
        dir.mkdirs(); //create folders where write files
        final File file = new File(dir, "my_video.mp4");

        Log.d("writePath", file.getPath());

        FileOutputStream output = new FileOutputStream(file);

        byte data[] = new byte[1024];
        long total = 0;

        while((count = input.read(data)) != -1)
        {
            total += count;
            //publishProgress("" + (int)((total*100) / lengthOfFile));
            output.write(data, 0, count);
        }

        output.flush();
        output.close();
        input.close();

        Log.d("download", "finished");

    }
    catch(Exception e)
    {

        Log.d("Exception", e.getMessage());
    }

This seems to succeed, but when I try to play the file with the following code, I get an error.

 // Play Video
    videoView = (VideoView)findViewById(R.id.surface_view);
    //

    File f = new File("/data/data/com.companyname.appname/files/videos/videoFilename.mp4");



    if(f.exists())
    {
        long len = f.length();
        String length = String.valueOf(len);
        Log.d("file", "exists");
        Log.d("length", (String)length);
    }
    else
    {
        Log.d("file", "does not exist");
    }

    //






    videoView.setMediaController(new MediaController(this));


    videoView.setVideoPath(f.getPath());
    videoView.start();

As can be seen from the code, before playing back I check if the file exists, as well as the size (the same size as the downloaded file), but it will not play, I assume that the file is damaged, but I don’t know why.

I have the following permissions set in the manifest

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERAL_STORAGE" />
+5
source
4

- , . .

+1

, . , /. :

                            file.setExecutable(true, false);
                            file.setReadable(true, false);
                            file.setWritable(true, false);
0

, URL- VideoView? , , :

VideoView video = new VideoView(mContext);
video.setMediaController(new MediaController(mContext));
video.setVideoURI(Uri.parse(this.url));

"mContext" , "this.url" - URL, VideoView.

0

, . , , , linux.

:

  • , FileDescriptor

    FileInputStream fileInputStream = new FileInputStream ( "/data/data/com.mypackage/myfile" ); mediaPlayer.setDataSource(fileInputStream.getFD());

    MediaPlayer, , .

  • .

    String basedir = ( "/data/data/com.companyname.appname/files/videos/videoFilename.mp4" ); file = this.ctx.getDir(basedir, Context.MODE_WORLD_READABLE);

, ! .

0
source

All Articles