# Loading Video from URL?

**URL:** <https://discourse.processing.org/t/loading-video-from-url/5480>\
**Category:** Coding Questions\
**Created:** [November 12, 2018, 6:35pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480 "2018-11-12T18:35:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arnoldovna](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arnoldovna](https://discourse.processing.org/u/Arnoldovna)\
**Post date:** [November 12, 2018, 6:35pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480/1 "2018-11-12T18:35:12Z")

</div>

hello.  
Im trying to create a Video with createVideo() from a youtube URL. In order to draw it on a canvas later on. Is this possible?

I saw something like this “URL.createObjectURL”. Is this pointing in the right direction?

Thank you very much in advance =)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 12, 2018, 6:38pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480/2 "2018-11-12T18:38:11Z")

</div>

Can you post a small example sketch that shows your approach?  
It is nearly impossible to say otherwise…

---

<div class="post-metadata">

**Author:** ![Arnoldovna](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arnoldovna](https://discourse.processing.org/u/Arnoldovna)\
**Post date:** [November 12, 2018, 7:14pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480/3 "2018-11-12T19:14:26Z")

</div>

```auto
var movie;
var canvas;
var playButton;
var playPressed = false;

var inputName;
var playingInThisMoment = false;
var movieEvents;
var inputField;
var submitButton;
var movieInput;

function setup() {
   
    inputField = createInput("insert url to video").addClass("urlInput");
    submitButton = createButton("submit").addClass("button");

    submitButton.mousePressed(submitFile);
    createP("drag your file here")
  
}

function draw() {

    if (playingInThisMoment) {
        movie.loadPixels();
        verticalS(...somecode...);

    } else if (!playingInThisMoment) {
        return;
    }
}

function playVideo() {
    if (playPressed) {
        movie.pause();
        playingInThisMoment = false;
        playButton.html("play");
    } else if (!playPressed) {
        playingInThisMoment = true;
      
        playButton.html("pause");
    }

    playPressed = !playPressed;
}

function submitFile() {
    if (!!inputField.value() && inputField.value() != "insert url to video") {
        movieInput = inputField.value();

        console.log(movieInput);

        //------>here getFile(.....movieInput.....) } HERE IS MY PROBLEM: IT WORKS WITH A LOCAL FILE BUT NOT URL <<-------------//
}

function getFile(file) {
    pixelDensity(1);

    movie = createVideo(file.data).id("video");
    movie.size(movieWidth, movieHeight);

    movieEvents = document.getElementById("video");

    movieEvents.onplaying = function() {
        console.log("The audio is now playing");
        playingInThisMoment = true;
    };

    movieEvents.onwaiting = function() {
        console.log("Wait! I need to buffer the next frame");
        // playingInThisMoment = false;
    };

    canvas = createCanvas(movieWidth, movieHeight).stroke(0);

    playButton = createButton("play")
    playButton.mouseClicked(playVideo);
}

```

---

<div class="post-metadata">

**Author:** ![Arnoldovna](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arnoldovna](https://discourse.processing.org/u/Arnoldovna)\
**Post date:** [November 12, 2018, 7:15pm UTC](https://discourse.processing.org/t/loading-video-from-url/5480/4 "2018-11-12T19:15:32Z")

</div>

this code might not work now. because i erased quite few code. Hope it’s more understandable now
