Using Processing for Android to play video

edited March 2016 in Android Mode

Hi,

I've been trying to get a video to play on my device using apwidgets. I've used the provided code:

import android.widget.VideoView; 
APVideoView videoView; 
APWidgetContainer container; 

void setup()
{
        container = new APWidgetContainer(this); //create a new widget container
        videoView = new APVideoView(10, 50, 240, 180, false); //create a new video view, without media controller
        videoView.setVideoPath("/sdcard/CornFlowerFromSprout.mp4"); //specify the path to the video file
        container.addWidget(videoView); //place the video view in the container
        videoView.start(); //start playing the video

}

void draw()
{
  background(0); //black background
  text(videoView.getDuration(), 10, 10); //display the length of the video in milliseconds
  text(videoView.getCurrentPosition(), 10, 30); //visa hur långt videon spelats 
}
void keyPressed() {
  if (key == CODED) {
    if (keyCode == LEFT) {
      videoView.seekTo(0); //"rewind"
    }
    else if (keyCode == RIGHT) {
      videoView.start(); //start playing video file
    }
    else if (keyCode == DPAD) {
      videoView.pause(); //pause the playing of the video file
    }
    else if (keyCode == DOWN) {
      videoView.setVideoPath("sdcard/VIDEO0001.3gp"); //switch to other video file
    }
  }
}

I keep getting the error "Can't play video". Does anyone have a solution to this error or any other way to play videos on my device from Processing?

Thank you for the help.

Answers

    • what os?
    • emulator or device?
    • what APWidgets library version?
    • is it only the error code you get?
    • try this code (from yours)

      import apwidgets.*;

      PVideoView videoView; PWidgetContainer container;

      void setup() { container = new PWidgetContainer(this); //create a new widget container videoView = new PVideoView(10, 50, 240, 180, false); //create a new video view, without media controller videoView.setVideoPath("/sdcard/CornFlowerFromSprout.mp4"); //specify the path to the video file container.addWidget(videoView); //place the video view in the container videoView.start(); //start playing the video

      }

      void draw() { background(0); //black background text(videoView.getDuration(), 10, 10); //display the length of the video in milliseconds text(videoView.getCurrentPosition(), 10, 30); //visa hur långt videon spelats } void keyPressed() { if (key == CODED) { if (keyCode == LEFT) { videoView.seekTo(0); //"rewind" } else if (keyCode == RIGHT) { videoView.start(); //start playing video file } else if (keyCode == DPAD) { videoView.pause(); //pause the playing of the video file } else if (keyCode == DOWN) { videoView.setVideoPath("sdcard/VIDEO0001.3gp"); //switch to other video file } } }

  • Activating the right permissions worked for me.

  • In case it helps anyone, I found that the "/sdcard/" path on my android tablet actually refers to the internal storage. The external storage (removable sd card) is located at "/storage/extSdCard/". I got it working this way after also going to the APDE settings and deselecting "Use Internal Storage". It plays videos now just fine without setting any sketch permissions.

  • @jaeba== it works for you but... you have to think to all cases what is ok on your tablet (depending from API level) is not ok for other phones && if you work for android you try to work for all (!) phones from API levelx to API levelx++ eg: have you looked at permissions since kitkat?

  • @akenaton thanks but I was just explaining exactly what worked for me in case someone else has a similar setup and wants to try it. I am not much of an android developer and do not claim to have good advice that will work for everyone. The only permissions-related thing I've ever looked at is the sketch permissions inside APDE. Sorry for any disappointment. :)

  • @jaeba==== ok; i understand; i am a professional developer, so... i know that if you work for android you HAVE to think to all cases... which is quite impossible but!--- --as Apde is (for me!) a poor solution, just have a look at the code i have left for another question (it was 2 ore 3 days before, find) here, && try, you ll see...

Sign In or Register to comment.