Playing of video from POST request

You must Login before you can answer or comment on any questions.

Hello, my idea is a video portal. The podcast videos has no fixed URL. The video will send from a web server after a POST request.

My idea:

Starting a xhr (POST) request and saving the input in a temp file. Now I link the video player to this tem file. Is it possible?

Rainer

1 Answer

This has very little to do with the mobile side of things. Most of this will have to occur on the server side. You send a POST to a server and the response has to be a download for the most part. All in all, I don't like this idea at all. If the video is on the server already, why for a download just to watch the video. Go ahead and POST to the server, the response will be a url with a token that makes the video available for that token, then stream the video to the device with an option to download if necessary. The download will still require the token, which has already been retrieved via the post request. Regardless, the best way to handle this would be to request the server, return a token, then use that token to request the video.

— answered 8 months ago by Anthony Decena
answer permalink
3 Comments
  • why for a download == why wait for a download, just watch the video

    — commented 8 months ago by Anthony Decena

  • The movie is only available in flash. On the site is a download link. But this link is not a link to a mp4 file. It makes a POST request and this request answered with the movie binary:

    http://lecture2go.uni-hamburg.de/veranstaltungen/-/v/12065

    Here my code to get the movie:

    exports.getVideo = function() {
        var self = {};
        self.tempFile = Ti.Filesystem.createTempFile();
        self.xhr = Titanium.Network.createHTTPClient();
        self.xhr.onload = function(e) {
        };
        self.xhr.onerror = function(E) {
        };
        self.xhr.ondatastream = function(e) {
        };
        self.xhr.file = self.tempfile;
        self.xhr.open('POST', 'http://fms1.rrz.uni-hamburg.de/download/getFile');
        self.xhr.send({
            l2g : 12065,
            type : "video"
        });
        return self.tempfile.nativePath;
    }

    — commented 8 months ago by Rainer Schleevoigt

  • I have written a full example program:

    var win = Titanium.UI.createWindow();
    win.open();
    var videoPlayer = Titanium.Media.createVideoPlayer({
        height : 300,
        width : Ti.UI.FILL,
        mediaControlStyle : Titanium.Media.VIDEO_CONTROL_DEFAULT,
        scalingMode : Titanium.Media.VIDEO_SCALING_ASPECT_FIT
    });
    require('video').get('12065', function(url) {
        videoPlayer.url = url;
        setTimeout(function() {
            videoPlayer.play();
            Ti.API.log(url);
        }, 2000);
    });
    win.add(videoPlayer);
    and here the video module:
    exports.get = function(id, _callback) {
        var self = {};
        self.got = false
        self.tempFile = Ti.Filesystem.createTempFile();
        self.xhr = Ti.Network.createHTTPClient();
        self.xhr.ondatastream = function(e) {
            if (self.got) return;
            self.got = true;
            _callback(self.tempFile.nativePath);
        };
        self.xhr.file = self.tempFile;
        self.xhr.open('POST', 'http://fms1.rrz.uni-hamburg.de/download/getFile');
        self.xhr.send({
            l2g : id,
            type : "video"
        });
    }
    Result: The videoscreen leaves blank (black), but the activity inducator on status bar is rotating. I thing the movie will saved in temFile, but the video player cannot read from this file. Any idea to solve the problem?

    — commented 8 months ago by Rainer Schleevoigt

Your Answer

Think you can help? Login to answer this question!