Embed for Youtube and Vimeo with Angular JS, PHP and MySQL

0

Good afternoon community of STACK OVERFLOW today I bring you a little problem that is breaking my head, it is related to regular expressions and embed videos from an external website (in this case: Youtube and Vimeo ).

The problem is that I want to obtain from the user a link from Youtube or Vimeo only that I do not know how to perform the regular expression of Vimeo to display it in a frame .

Here's the example of YouTube , it should be mentioned that these lines of code work perfectly.

$scope.changeDoc = function(goto){  

    $scope.current_doc = (goto == 1) ? $scope.current_doc+1 : $scope.current_doc-1; 
        if($scope.current_doc == 0){
            $(".left-arrow").hide();
        }
        else if($scope.current_doc == (docs.length-1)){
            $(".right-arrow").hide();
        }
        else{           
            $(".left-arrow").show();
            $(".right-arrow").show();
        }
        $scope.viewer.title = docs[$scope.current_doc].name;

        console.log($scope.current_doc);
        console.log(docs.length);

            if(docs.length-1 == $scope.current_doc && docs.length == 10){     

                var youTubeUrl = docs[$scope.current_doc].url;
                console.log(youTubeUrl);        

                var regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/;
                var match = youTubeUrl.match(regExp);
                if (match && match[2].length == 11)
                   youTubeId = match[2];
                else youTubeId = '';

                var url = "//www.youtube.com/embed/" + youTubeId;
                console.log(url);


                $scope.viewer.source = $sce.trustAsResourceUrl(url);   
            }
            else{
                $scope.viewer.source = "../docs/"+docs[$scope.current_doc].url;   
            }       
    };

All this code is working without problem and Embed Youtube does it perfectly when consulting user documents. I hope you can help me friends from the community.

    
asked by Harrison Olvera 28.05.2018 в 19:20
source

0 answers