2

I'm trying to play a downloaded video using the VideoView and got the following error:

04-14 13:10:49.057: E/MediaPlayer(2229): error (1, -2147483648)

This is how I download a video:

private String getDataSource(InputStream stream) throws IOException { 
    if (stream == null)
        throw new RuntimeException("stream is null");

    File temp;

    if (!canSaveVideo) {
        temp = File.createTempFile("mediaplayertmp", ".mp4");
        temp.deleteOnExit();
    }
    else {
         File dir = new File(localFilePath);
         if (!dir.exists()) {
             dir.mkdirs();
         }
         //localFilePath = Environment.getExternalStorageDirectory().getAbsolutePath();
        temp = new File(localFilePath + "VID_" + localSenderID + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + ".mp4");
    }


    String tempPath = temp.getAbsolutePath();
    FileOutputStream out = new FileOutputStream(temp);
    byte buf[] = new byte[256000];
    do {
        int numread = stream.read(buf);
        if (numread <= 0)
            break;
        out.write(buf, 0, numread);
        out.flush();
    } while (true);
    out.flush();
    out.close();

    /*
    try {
        stream.close();
    } catch (IOException ex) {
        Log.e("tag", "error: " + ex.getMessage(), ex);
    }
    */

    temp.setExecutable(true,false);
    temp.setReadable(true,false);
    temp.setWritable(true,false);

    return tempPath;
}

The above code downloads a video file from Socket.getInputStream() and returns the video's absolute path. It works fine since I can play the downloaded video files manually.

However, when I tried to play the downloaded video files using VideoView, it throws the Error (1, -2147483648).

This is how I play the video using VideoView:

private void playVideo(String videoPath) {
    try {
        videoView.setVideoPath(videoPath);
        videoView.start();
        videoView.requestFocus();
    } catch (Exception e) {
        Log.e("tag", "error: " + e.getMessage(), e);
        if (videoView != null) {
            videoView.stopPlayback();
        }
    }
}

I believe this line:

videoView.setVideoPath(videoPath); 

causes the error, since when I printed out the tempPath in getDataSource() method and passed it directly to the videoView like this, it worked:

videoView.setVideoPath("/sdcard/Surveillance/download/VID_KDuong_20140414_130853.mp4");

Does anyone know how to solve this problem?

Chris
  • 26,544
  • 5
  • 58
  • 71
KeiD
  • 95
  • 3
  • You're highly encouraged to change your username, by the way! You can do that on your [profile page](http://stackoverflow.com/users/edit/3532975). (If that link doesn't work, simply go to your profile and click "edit"). – Chris Apr 14 '14 at 19:18

0 Answers0