Created
March 20, 2014 20:35
-
-
Save chmiiller/9673255 to your computer and use it in GitHub Desktop.
Youtube embed videoplayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convert(id){ | |
/* | |
* using https://github.com/rborn/TitaniumYoutubePlayer | |
* or | |
* https://github.com/bob-sims/ytPlayer | |
*/ | |
Titanium.API.info('Video id ' + id); | |
var client = Ti.Network.createHTTPClient(); | |
client.onload = function () { | |
var json = (this.responseText.substring(4, this.responseText.length)); | |
//Titanium.API.info(json); | |
var response = JSON.parse(json); | |
var isHighQuality = response.content['player_data']['fmt_stream_map'] != null; | |
var streamUrl = isHighQuality ? response.content['player_data']['fmt_stream_map'][0].url : ''; | |
if(!isHighQuality) { | |
Ti.API.info('using low quality video because fmt_stream_map does not exist in json response, User-Agent probably is not being sent correctly'); | |
} | |
videoPlayer.url = streamUrl; | |
}; | |
client.setRequestHeader('Referer', 'http://www.youtube.com/watch?v=' + id); | |
client.setRequestHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.14 (KHTML, like Gecko) Version/6.0.1 Safari/536.26.14'); | |
client.open('GET', 'http://m.youtube.com/watch?ajax=1&layout=mobile&tsp=1&utcoffset=330&v=' + id); | |
client.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment