Eventos para YouTube incrustados en Mobile Safari, iPhone (devolución de llamada al detener)

I'm working on this mobile site, where I need to play a YouTube video in Fullscreen. So far, so good. Just a YouTube embed, and voilá.

But! (Yeah, there's always a «but»)

I need to fire an event (namely, a JS function) when the video ends. I figured Safari translated the YT embed a una <video> tag, so I tried using HTML5s video events, but didn't work:

$('video').bind('ended', function () {
    alert('Video has ended');
});

This fine piece of code works when using a <video> tag directly, but not when using a YT embed.

So, any ideas on how can I fire this function when the YT video has finished playing?

¡Gracias!

preguntado el 08 de noviembre de 11 a las 16:11

Is it possible that it's not setting the ID of the YT embed to 'video'? If so, see if you have an alternate way of finding the item within the DOM. -

El selector $('video') matches every <video> tag. It needs a # to match by ID. -

In that case, it's possible Apple's got a Safari-specific tag that $('video') isn't matching. There has to be some way to output the source of the page, though. -

1 Respuestas

When you create your YT instance, you can provide a hash that maps events to handlers. Provide a handler for the onStateChange event, and test for the eventType that corresponds to video end ( 0 ).

new YT.Player('player', {
    events: {
        'onStateChange' : function ( eventType ) { if ( eventType.data == 0 ) { ... } }
    }
} );

See the section of YouTube's JavaScript API for Eventos

Respondido 12 Abr '12, 01:04

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.