Skip to content

Instantly share code, notes, and snippets.

@LHIOUI
Last active August 29, 2015 14:07
Show Gist options
  • Save LHIOUI/905da5e44203e38d2993 to your computer and use it in GitHub Desktop.
Save LHIOUI/905da5e44203e38d2993 to your computer and use it in GitHub Desktop.
Titanium commonJS module to play vimeo video on Ti.Media.VideoPlayer.
//
// tiVimeo.js
//
// Created by Coyote on 2014-10-08.
// Copyright 2014 Coyote. All rights reserved.
//
var VimeoVideo = function(id, callback) {
var client = Ti.Network.createHTTPClient();
client.onload = function(response) {
Ti.API.debug('on load ');
var json = JSON.parse(client.responseText);
if ( typeof json["request"] != 'undefined') {
var codecs = json["request"]["files"][json["request"]["files"]["codecs"][0]];
if ( typeof codecs["mobile"] != 'undefined') {
callback(codecs["mobile"].url);
Ti.API.debug('mobiles ');
} else if ( typeof codecs["sd"] != 'undefined') {
callback(codecs["sd"].url);
Ti.API.debug('sd ');
} else if ( typeof codecs["hd"] != 'undefined') {
callback(codecs["hd"].url);
Ti.API.debug('hd ');
} else {
callback('undefined');
Ti.API.debug('undefined ');
}
} else
callback('undefined');
};
client.onerror = function(e) {
Ti.API.error('error ' + JSON.stringify(e));
callback('undefined');
};
client.open('GET', 'http://player.vimeo.com/video/' + id + '/config');
client.send();
};
/**
* @param {Object} id of vimeo video
*/
exports.palyVimeo = function(id) {
VimeoVideo(id, function(url) {
Ti.API.debug('url ' + url);
if (url != 'undefined') {
var win = Ti.UI.createWindow();
var video = Titanium.Media.createVideoPlayer();
video.url = url;
win.backgroundColor = "#fff";
win.orientationModes = [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT];
win.add(video);
win.addEventListener('open', function(e) {
video.play();
});
win.open();
} else
alert('vimeo video non valid');
});
};
//////////////////////////////////////////
// usage :
// var palyVimeo=require('tiVimeo');
// palyVimeo('52899610');
//////////////////////////////////////////
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment