Search Unity

Video Unity 5.6.1 Video Player url youtube support

Discussion in 'Audio & Video' started by mdhvgpta, Jul 13, 2017.

  1. mdhvgpta

    mdhvgpta

    Joined:
    Sep 2, 2015
    Posts:
    3
    Hi,
    Is there an alternate to stream youtube videos directly from the new video player url source? I tried copy pasting a youtube url but it fails to load. It seems that video urls with a .mp4 at the end is only supported.
     
    taguados likes this.
  2. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Same problem. No solution?

    From here, seems a script changing the parsing should work.
     
  3. jonathancsaldana

    jonathancsaldana

    Joined:
    Jun 2, 2017
    Posts:
    2
    It is possible play videos from youtube url.

    You can try with this tutorial

    (it is in Spanish).

    Or you can search something about youtube videohelperdownload.

    this works on android and IOS.
     
    Mechanism253 and taguados like this.
  4. jkuijt

    jkuijt

    Joined:
    Nov 30, 2013
    Posts:
    1
    One way to play YouTube videos is to include this library into your project: https://github.com/flagbug/YoutubeExtractor

    Not only does this library provide the ability to download a YouTube video but also to create a streaming link for you.

    You can follow the example script on the project page up until creating a VideoInfo object. The VideoInfo object has a variable DownloadUrl which is a direct link to either a webm or mp4 file. For streaming you will need a mp4 file.

    You will need a script to then pass this streaming link to the VideoPlayer url variable and Unity will play the video as you would except.
     
    taguados likes this.
  5. killycal

    killycal

    Joined:
    Mar 13, 2017
    Posts:
    1
    So with this extractor, I can connect to a livestream from youtube?
     
  6. IDEA_Developer

    IDEA_Developer

    Joined:
    Feb 27, 2018
    Posts:
    1
    Just out of curiosity, did you manage to get this to work jkuijt?
    I tried the library, and besides the problem with the net.http library (wich I solved by compiling the library and forcing the net.http to be included) it always throws the same exception, no matter what


    TlsException: Invalid certificate received from server. Error code: 0xffffffff800b010a
    (wrapper remoting-invoke-with-check) Mono.Security.Protocol.Tls.Handshake.HandshakeMessage:Process()
    Rethrow as IOException: The authentication or decryption has failed.
     
  7. GuruJeya14

    GuruJeya14

    Joined:
    Jun 29, 2017
    Posts:
    9
    I have used the following php, and it returns the youtube video file links, individually with respect to the resolution.
    Referred from here.

    just hit the php with the 'url', i.e., the youtube video link, and you will receive the result as json.

    I have just changed it as POST instead of GET. You can use whatever suits you.
    (Give a thumbs up if it helps :))


    <?php
    //Returns the json data containing the individual url for individual video quality files
    header('Access-Control-Allow-Origin: *');
    header('Content-Type: application/json');
    if(isset($_POST['url']) && $_POST['url'] != ""){
    parse_str( parse_url( $_POST['url'], PHP_URL_QUERY ), $vars );

    $id=$vars['v'];
    $dt=file_get_contents("http://www.youtube.com/get_video_info?video_id=$id&el=embedded&ps=default&eurl=&gl=US&hl=en");
    //var_dump(explode("&",$dt));
    if (strpos($dt, 'status=fail') !== false) {

    $x=explode("&",$dt);
    $t=array(); $g=array(); $h=array();
    foreach($x as $r){
    $c=explode("=",$r);
    $n=$c[0]; $v=$c[1];
    $y=urldecode($v);
    $t[$n]=$v;
    }
    $x=explode("&",$dt);
    foreach($x as $r){
    $c=explode("=",$r);
    $n=$c[0]; $v=$c[1];
    $h[$n]=urldecode($v);
    }
    $g[]=$h;
    $g[0]['error'] = true;
    $g[0]['instagram'] = "egy.js";
    $g[0]['apiMadeBy'] = 'El-zahaby';
    echo json_encode($g,JSON_PRETTY_PRINT);

    }else{

    $x=explode("&",$dt);
    $t=array(); $g=array(); $h=array();
    foreach($x as $r){
    $c=explode("=",$r);
    $n=$c[0]; $v=$c[1];
    $y=urldecode($v);
    $t[$n]=$v;
    }
    $streams = explode(',',urldecode($t['url_encoded_fmt_stream_map']));
    foreach($streams as $dt){
    $x=explode("&",$dt);
    foreach($x as $r){
    $c=explode("=",$r);
    $n=$c[0]; $v=$c[1];
    $h[$n]=urldecode($v);
    }
    $g[]=$h;
    }
    echo json_encode($g,JSON_PRETTY_PRINT);
    // var_dump( $g[1]["quality"],true);
    }
    }else{
    @$myObj->error = true;
    $myObj->msg = "there is no youtube link";

    $myObj->madeBy = "El-zahaby";
    $myObj->instagram = "egy.js";
    $myJSON = json_encode($myObj,JSON_PRETTY_PRINT);
    echo $myJSON;
    }
     
    Gomer22, GTaylorRetro and Straafe like this.
  8. Illidan-Shtormraydj

    Illidan-Shtormraydj

    Joined:
    Dec 29, 2018
    Posts:
    2
    where to put this script?
     
    GTaylorRetro likes this.
  9. GTaylorRetro

    GTaylorRetro

    Joined:
    Apr 11, 2019
    Posts:
    1
    Hey Illidan-Shtormraydj,

    Did you manage to figure out where to put the php script, to get youtube vids streaming in your unity game?

    Thanks in advance!!
     
  10. tarun_bhardwaj

    tarun_bhardwaj

    Joined:
    May 9, 2019
    Posts:
    1
    To use PHP script you need need Apache server. If you're using that app for windows, Mac or Linux then use xampp to run PHP script on your system. If you want to access the PHP script globally then you may use free Linux hosting providers online.
     
    GuruJeya14 likes this.