Hi everyone!
After trying to get this to work by searching and testing some days a week I’ve finally got Youtube videos playing in an acceptable way using Corona SDK. 
Currently it connects to a PHP file on a server which collects the post data with the video URL and then sends it to another PHP file which is made by this guy: http://www.masnun.me/2011/05/17/phptube-a-php-class-to-get-download-links-from-youtube-watch-videos.html#comments
Almost everything works perfect!
My problem is that I can only get it to work if the server has the same ip-adress as the device because the URL that you gets only work on the device that requested it. So you can test this if you use something like xampp. I need a solution that makes it possible to have the PHP files in the project folder or have them on a server with another IP-adress and make it work anyway.
Here is my project:
http://d.pr/f/oEqd
And here is the code, change the URL in main.lua to test it with other videos:
main.lua
io.output():setvbuf('no')
print();print("");print()
-- require controller module
local storyboard = require "storyboard"
local widget = require "widget"
http = require("socket.http")
ltn12 = require("ltn12")
url = require("socket.url")
local is\_supported = audio.supportsSessionProperty
if (is\_supported) then
audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)
end
-- load first screen
-- The main group
mainGroup = display.newGroup()
-- The main function
local function main()
-- Add the group from director class
--mainGroup:insert(director.directorView)
loggedin = nil
--storyboard.gotoScene( "mainpage" )
youtubeVideoURL = "http://www.youtube.com/watch?v=0e4p\_5J\_bZY"
local function networkListener( event )
if ( event.isError ) then
print( "Network error!")
else
print (event.response )
url = event.response
function trimr(s)
return s:find'^%s\*$' and '' or s:match'^(.\*%S)'
end
url = trimr(url)
media.playVideo( url, media.RemoteSource, true)
end
end
postData = "videoURL=" .. youtubeVideoURL
local params = {}
params.body = postData
network.request( "http://localhost/youtubedl/index.php", "POST", networkListener, params)
return true
end
main()
index.php
<?php <br>require\_once 'PhpTube.php';
$tube = new PhpTube();
if (isset($\_POST['videoURL'])){
$videoURL = $\_POST['videoURL'];
$videos = $tube-\>getDownloadLink($videoURL);
echo($videos[0]);
}
?\>
PhpTube.php
[code]
<?php/\* \* @package PhpTube - A PHP class to get youtube download links \* @author Abu Ashraf Masnun
* @website http://masnun.com
*
*/
class PhpTube
{
/**
* Parses the youtube URL and returns error message or array of download links
*
* @param $watchUrl the URL of the Youtube video
* @return string|array the error message or the array of download links
*/
public function getDownloadLink($watchUrl)
{
//utf8 encode and convert "&"
$html = utf8_encode($this->_getHtml($watchUrl));
$html = str_replace("\u0026amp;","&",$html);
//get format url
preg_match_all('/url_encoded_fmt_stream_map\=(.*)/',$html,$matches);
$formatUrl = urldecode($matches[1][0]);
//split the format url into individual urls
$urls = preg_split('/url=/', $formatUrl);
$videoUrls = array();
foreach($urls as $url)
{
// do necessary processings
$url = urldecode($url);
$urlparts = explode(";",$url);
$url = $urlparts[0];
$urlparts = explode(",",$url);
$url = $urlparts[0];
// append to container
if(strlen($url) > 450 && strlen($url) < 600)
{
$length = strlen($url);
$characters = 3;
$start = $length - $characters;
$end = substr($url , $start ,$characters);
if($end == "mp4" ){
$videoUrls[] = $url;
}
}
}
return $videoUrls;
}
/**
* A wrapper around the cURL library to fetch the content of the url
*
* @throws Exception if the curl extension is not available (or loaded)
* @param $url the url of the page to fetch the content of
* @return string the content of the url
*/
private function _getHtml($url)
{
if (function_exists("curl_init"))
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
return curl_exec($ch);
}
else
{
throw new Exception("No cURL module available");
}
}
}
[/code] [import]uid: 24111 topic_id: 25783 reply_id: 325783[/import]


[import]uid: 24111 topic_id: 25783 reply_id: 104267[/import]