Viewed   214 times

Can anyone give me an idea how can we show or embed a YouTube video if we just have the URL or the Embed code?



You have to ask users to store the 11 character code from the youtube video.

For e.g.

The eleven character code is : Ahg6qcgoay4

You then take this code and place it in your database. Then wherever you want to place the youtube video in your page, load the character from the database and put the following code:-

e.g. for Ahg6qcgoay4 it will be :

<object width="425" height="350" data="" type="application/x-shockwave-flash"><param name="src" value="" /></object>
Tuesday, December 13, 2022

As I can't find any way to load the rtsp URL in video view (for all devices & android versions), I solved my problem with another work around. I used a webview to embed the youtube player within it, and this method working nicely in all tested devices.

Here is my code:

mWebView.loadUrl("" + videoID + "?autoplay=1&vq=small");
mWebView.setWebChromeClient(new WebChromeClient());

Thank you very much for all your help guys.

Thursday, August 18, 2022

you can easily do this with the Youtube Player API

If you have a read through that document, you'll see it's pretty easy to have your own controls and extend the player.


// Get element holding the video (embed or object)
var player = document.getElementById("myYouTubePlayer");

//Create a simple function and check if player exists
function play() {
    if(player) {

Then in your HTML simply

<a href="#" onclick="play()">Play Youtube Video</a>
Thursday, September 1, 2022

Using the Youtube IFrame API, you can do this easily.

The only part you need to configure here is the array of youtube IDs. You can retrieve those from the part after the /v/ in the URL (If need be, you can modify the javascript to load URLs instead of IDs. I just like this way better.

<div id="player"></div>
<script src="//"></script>

     * Put your video IDs in this array
    var videoIDs = [

    var player, currentVideoId = 0;

    function onYouTubeIframeAPIReady() {
        player = new YT.Player('player', {
            height: '350',
            width: '425',
            events: {
                'onReady': onPlayerReady,
                'onStateChange': onPlayerStateChange

    function onPlayerReady(event) {[currentVideoId]);

    function onPlayerStateChange(event) {
        if ( == YT.PlayerState.ENDED) {
            if (currentVideoId < videoIDs.length) {
Sunday, November 27, 2022

It is possible to play the audio in the background. However , you are not allowed to do so.

This violation of the Youtube API is cause for immidiate removal from the play store.

Official answer:

During review, we found that your app violates the Prohibited Actions provision of the Content Policy.

We have determined that your app enables background playing of YouTube videos, which is a violation of the YouTube API Terms of Service: "Your API Client will not, and You will not encourage or create functionality for Your users or other third parties to: (8) separate, isolate, or modify the audio or video components of any YouTube audiovisual content made available through the YouTube API;"

Saturday, November 5, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :