EzDevInfo.com

youtube interview questions

Top youtube frequently asked interview questions

YouTube Iframe embed auto play

I am trying to embed the new iframe version of a YouTube video and get it to auto play.

As far as I can tell, there is no way of doing this by amending flags to the URL. Is there a way to do it by using javascript & the API?


Source: (StackOverflow)

Chrome YouTube cast_sender.js console error

I recently started receiving the following console errors, without any code changes taking place.

I did not install any extensions recently.

Failed to load resource: net::ERR_FAILED chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js
Failed to load resource: net::ERR_FAILED chrome-extension://hfaagokkkhdbgiakmmlclaapfelnkoah/cast_sender.js
Failed to load resource: net::ERR_FAILED chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js
Failed to load resource: net::ERR_FAILED chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js
Failed to load resource: net::ERR_FAILED

I have several youtube player embeds on the page that are triggering this error, but they are simple:

<iframe width="100%" height="100%" src="http://www.youtube.com/embed/OUR_YOUTUBE_ID?showinfo=0&amp;wmode=transparent" frameborder="0" allowfullscreen=""></iframe>

Has anybody else experienced this?


Source: (StackOverflow)

Advertisements

Force HTML5 youtube video

Regarding the Youtube API Blog they are experimenting their new HTML5 Video Player.

Apparently to play a video in html5, you have to use the iframe embedding code :

<iframe class="youtube-player" type="text/html" width="640" height="385"
  src="http://www.youtube.com/embed/VIDEO_ID" frameborder="0">
</iframe>

But if the client has not joined the HTML5 Trial, the player will automatically fall back into the flash player even if the client's browser is HTML5 video capable.

How to force the HTML5 video playback if the browser supports it, even if the users is not yet involved in the HTML5 Trial ?

Otherwise how to disable the flash fallback ?

EDIT:

It's possible to force HTML player through links to Youtube Video, but I need this kind of feature for embedded videos.


Source: (StackOverflow)

How can I autoplay a video using the new embed code style for Youtube?

I can't work out how to autoplay a video using the new embed code style for Youtube. I tried adding &autoplay=1 to the url, which worked with the old style, but it didn't work. For example, http://www.youtube.com/embed/JW5meKfy3fY is the embed link, but http://www.youtube.com/embed/JW5meKfy3fY&autoplay=1 doesn't work. Can anyone tell me how to do it? Thanks


Source: (StackOverflow)

Play YouTube videos with MPMoviePlayerController instead of UIWebView

Hello I'm trying to stream some youTube videos using the MPMoviePlayerController but I'm having some problems. The code i'm using is pretty simple and I can play .m4v videos by passing a URL to initWithContentURL. When I launch the movie player the player comes up but just goes away after about 20 seconds. When I try it in the simulator I get an alert view that says the server is not configured correctly. Is there an argument I need to pass with the URL to get a specific type of video feed from google?

NSURL *videoURL = [NSURL URLWithString:@"http://www.youtube.com/v/HGd9qAfpZio&hl=en_US&fs=1&"];
MPMoviePlayerController *moviePlayer;
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];

[moviePlayer play];

I've also tried the following URL's http://www.youtube.com/watch?v=HGd9qAfpZio

I have also seen the argument &format=1 and tried to add that to the end of both of the strings but no luck.

Thanks in advance for any help!


Source: (StackOverflow)

Bootstrap 3 and Youtube in Modal

I'm trying to use the Modal feature from Bootstrap 3 to show my Youtube video. It works, but I can't click on any buttons in the Youtube video.

Any help on this?

Here's my code:

<div id="link">My video</div>

<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            </div>
            <div class="modal-body">
                <iframe width="400" height="300" frameborder="0" allowfullscreen=""></iframe>
            </div>
        </div>
    </div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/jquery-1.10.1.min.js"><\/script>')</script>
<script src="js/bootstrap.min.js"></script>
<script>
    $('#link').click(function () {
        var src = 'http://www.youtube.com/v/FSi2fJALDyQ&amp;autoplay=1';
        $('#myModal').modal('show');
        $('#myModal iframe').attr('src', src);
    });

    $('#myModal button').click(function () {
        $('#myModal iframe').removeAttr('src');
    });
</script>

Source: (StackOverflow)

Methods of removing the youtube iframe api console error - "blocked a frame with origin..." in chrome console

I'm using the youtube iframe api and get the following console error relating to the blocking of a frame with origin http://www.youtube.com. Was wondering if anyone can explain why this error is only appearing in the chrome console and if there are any ways to prevent this happening?

Error:

Blocked a frame with origin "http://www.youtube.com" from accessing a frame with origin "http://youtubetest.appspot.com". Protocols, domains, and ports must match.


Source: (StackOverflow)

How to receive NSNotifications from UIWebView embedded YouTube video playback

I didn't received any notifications for MPMoviePlayerController. What am I doing wrong?

I use following logic.

I'm begining to play youtube video in UIWebView. UIWebView calls a standard MPMoviePlayerController. I don't control MPMoviePlayerController because I didn't instantiate MPMoviePlayerController.

I run youtube's clip with autoplay (1 second delay):

[self performSelector:@selector(touchInView:) withObject:b afterDelay:1];

My code is:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loadStateDidChange:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerDidExitFullscreenNotification object:nil];

    [self embedYouTube];
}

- (void)loadStateDidChange:(NSNotification*)notification
{
    NSLog(@"________loadStateDidChange");
}

- (void)playbackDidFinish:(NSNotification*)notification
{
    NSLog(@"________DidExitFullscreenNotification");
}

- (void)embedYouTube
{
    CGRect frame = CGRectMake(25, 89, 161, 121);
    NSString *urlString = [NSString stringWithString:@"http://www.youtube.com/watch?v=sh29Pm1Rrc0"];

    NSString *embedHTML = @"<html><head>\
    <body style=\"margin:0\">\
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed>\
    </body></html>";
    NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
    UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
    videoView.delegate = self;

    for (id subview in videoView.subviews)
        if ([[subview class] isSubclassOfClass: [UIScrollView class]])
            ((UIScrollView *)subview).bounces = NO;

            [videoView loadHTMLString:html baseURL:nil];
    [self.view addSubview:videoView];
    [videoView release];
}

- (void)webViewDidFinishLoad:(UIWebView *)_webView 
{
    UIButton *b = [self findButtonInView:_webView];
    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(touchInView:) object:b];
    [self performSelector:@selector(touchInView:) withObject:b afterDelay:1];
}

- (UIButton *)findButtonInView:(UIView *)view 
{
    UIButton *button = nil;

    if ([view isMemberOfClass:[UIButton class]]) {
        return (UIButton *)view;
    }

    if (view.subviews && [view.subviews count] > 0) 
    {
        for (UIView *subview in view.subviews) 
        {
            button = [self findButtonInView:subview];
            if (button) return button;
        }
    }
    return button;
}

- (void)touchInView:(UIButton*)b
{
    [b sendActionsForControlEvents:UIControlEventTouchUpInside];
}

UPDATE: I'm creating application that plays youtube's video. You can run playlist and you will see first video. When first video has ended, second video begins play automatically and so on.

I need to support ios 4.1 and above.

UPDATE2: @H2CO3 I'm trying to use your url-scheme, but it don't works. Delegate method didn't called on exit event. I added my html url to log. It is:

<html><head>    <body style="margin:0">    
<script>function endMovie() 
{document.location.rel='nofollow' href="somefakeurlscheme://video-ended";} 
 </script>      <embed id="yt" src="http://www.youtube.com/watch?v=sh29Pm1Rrc0"        
 onended="endMovie()" type="application/x-shockwave-flash"  
 width="161" height="121"></embed>  
 </body></html>

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
  if ([[[request URL] absoluteString] hasPrefix:@"somefakeurlscheme://video-ended"]) 
  {
    [self someMethodSupposedToDetectVideoEndedEvent];
    return NO; // prevent really loading the URL
   }
  return YES; // else load the URL as desired
}

UPDATE3 @Till, I cann't caught UIMoviePlayerControllerDidExitFullscreenNotification, but I found MPAVControllerItemPlaybackDidEndNotification. MPAVControllerItemPlaybackDidEndNotification appears when playback video is ended.

But I don't understand how do I catch onDone notifications?


Source: (StackOverflow)

FF3/Windows CSS z-index problem with YouTube player

I'm stuck on what appears to be a CSS/z-index conflict with the YouTube player. In Firefox 3 under Windows XP, Take a look at this page: http://spokenword.org/program/21396 Click on the Collect button and note that the pop-up <div> appears under the YouTube player. On other browsers the <div> appears on top. It has a z-index value of 999999. I've tried setting the z-index of the <object> element containing the player to a lower value, but that didn't work. Any idea how to get the pop-up to appear over the player?


Source: (StackOverflow)

How to embed YouTube videos in PHP?

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?


Source: (StackOverflow)

How does Youtube's HTML5 video player control buffering?

I was watching a youtube video and I decided to investigate some parts of its video player. I noticed that unlike most HTML5 video I have seen, Youtube's video player does not do a normal video source and instead utilizes a blob url as the source.

Previously I have tested HTML5 videos and I found that the server starts streaming the whole video from the start and buffers in the background the complete rest of the video. This means that if your video is 300 megs, all 300 megs will be downloaded. If you seek to the middle, it will start downloading from the seek position all the way to the end.

Youtube does not work this way (at least in chrome). Instead it manages to control buffering so it only buffers a certain amount while paused. It also seems to only buffer the relevant pieces, so if you skip around it will make sure not to buffer pieces that are unlikely to be watched.

In my attempts to investigate how this worked, I noticed the video src tag has a value of blob:http%3A//www.youtube.com/ee625eee-2802-49b2-a13f-eb374d551d54, which pointed me to blobs, which then led me to typed arrays. Using those two resources I am able to load a mp4 video into a blob and display it in a HTML5 video tag.

However, what I am now stuck on is how Youtube deals with the pieces. Looking at the network traffic it appears to sends requests to http://r6---sn-p5q7ynee.c.youtube.com/videoplayback which returns binary video data back in chunks of 1.1mb. It also seems worth noting that most normal requests due to HTML5 video requests seem to receive a 206 response code back while it streams, yet youtube's playvideo calls get a 200 back.

I tried to attempt to only load a range of bytes (via setting the Range http header) which unfortunately failed (I'm assuming because there was no meta-data for the video coming with the video).

At this point I'm stuck on figuring out how Youtube accomplishes this. I came up with several ideas though none of which I am completely sold on:

1) Youtube is sending down self contained video and audio chunks with each /videoplayback call. This seems like a pretty heavy burden on the upload side and it seems like it would be difficult to stitch these together to make it appear like it's one seemless video. Also, the video tag seems to think it's one full video, judging from calling $('video').duration and $('video').currentTime, which leads me to believe that the video tag thinks it's a single video file. Finally, the vidoe src tag never changes which makes me believe it is working with a singular blob and not switching out blobs.

2) Youtube constructs an empty blob pre-sized to the full video array and updates the blob with pieces as it downloads it. It would then make sure the user has not gotten too close to the last downloaded piece (to prevent the user from entering an undownloaded section of the blob). The problem that I see with this that I don't see any way to dynamically update a blob through javascript (although maybe I'm just having trouble googling for it)

3) Youtube downloads the meta data and then starts constructing the blob in order by appending the video pieces as it downloads them. The problem I see with this method is I don't understand how it would handle seeks in post-buffered territory.

Maybe I"m just missing an obvious answer that's right in front of me. Anyone have any ideas?


edit: I just thought of a fourth option. Another idea is they might use the file API to write the binary chunks to a file and use that file to stream off of. The file API seems to have the ability to seek to specific positions, therefore allowing you to fill a video with empty bytes and fill them in as they are received. This would definitely accommodate video seeking as well.


Source: (StackOverflow)

Youtube Api to fetch all videos on a Channel

We need video-list by channel-name of YouTube (using API)

We can get Channel-list (only ChannelName) by using below API

https://gdata.youtube.com/feeds/api/channels?v=2&q=tendulkar

below is a direct link of channels

https://www.youtube.com/channel/UCqAEtEr0A0Eo2IVcuWBfB9g

or

WWW.YouTube.com/channel/HC-8jgBP-4rlI

Now, we need videos of channel >> UCqAEtEr0A0Eo2IVcuWBfB9g or HC-8jgBP-4rlI

we tried

https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&User=UC7Xayrf2k0NZiz3S04WuDNQ https://gdata.youtube.com/feeds/api/videos?v=2&uploader=partner&q=UC7Xayrf2k0NZiz3S04WuDNQ

But, it does not help. We need all the videos posted on the channel. Videos uploaded to a channel can be from multiple users thus I don't think providing user parameter would help..


Source: (StackOverflow)

Replace url from youtube to embed code - Error: Permission denied to access property 'toString'

I have this code and this error in FireBug:

Error: Permission denied to access property 'toString'

How can i fix this error?

HTML:

<div class="yturl">http://www.youtube.com/watch?v=UNMLEZrukRU</div>

JS:

$("div.yturl").each(function(){
    var regex = /(\?v=|\&v=|\/\d\/|\/embed\/|\/v\/|\.be\/)([a-zA-Z0-9\-\_]+)/;
    var youtubeurl = $(this).text();
    var regexyoutubeurl = youtubeurl.match(regex);
    if (regexyoutubeurl) 
    {
         $(this).html("<iframe width=\"390\" height=\"315\" src=\"http://www.youtube.com/embed/"+regexyoutubeurl[2]+"\" frameborder=\"0\" allowfullscreen></iframe>");
    }
});

DEMO: http://jsfiddle.net/9e48p/


Source: (StackOverflow)

Show Youtube video source into HTML5 video tag?

I'm trying to put a YouTube video source into the HTML5 <video> tag, but it doesn't seem to work. After some Googling, I found out that HTML5 doesn't support YouTube video URLs as a source.

Can you use HTML5 to embed YouTube videos? If not, is there any workaround?


Source: (StackOverflow)

How to stop youtube video playing in Android webview?

How can I stop a YouTube video which is played in my webview? When I click on the back button the video doesn't stop and instead continues in the background.

Code:

webView = (WebView) findViewById(R.id.webview); 
webView.getSettings().setPluginsEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setBuiltInZoomControls(false); 
webView.getSettings().setSupportZoom(false);
webView.loadData(myUrl,"text/html", "utf-8");

Source: (StackOverflow)