[wp-hackers] stopping an embedded video with javascript

Chris McCoy chris at lod.com
Wed Sep 11 15:48:19 UTC 2013


if you look

https://developers.google.com/youtube/js_api_reference


the player.stopVideo() will do what you want.

to do a hyper link to stop the video the example would be something like

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

function stop() {
    if(player) {
        player.stopVideo();
    }
}

<a href="#" onclick="stop()">Stop Youtube Video</a>


hopefully this can guide you to something you can use.



On 2013-09-11 9:04 AM, "Nikola Nikolov" <nikolov.tmw at gmail.com> wrote:

>Hi Steve. I've found out that usually the YouTube video will reload
>itself(and stop unless it has autoplay) if it's visibility get's changed.
>What I mean by this is that you can hide the video or one of it's
>containing elements and show it again with jQuery(or other JavaScript), I
>believe you can also change either z-index or the display CSS properties.
>
>So if that's all you're looking for - I think you can try playing in this
>direction, since it might be easier. Otherwise I'd look into the
>documentation - can't help you with the JS API though :(
>
>
>On Wed, Sep 11, 2013 at 2:56 PM, Chris McCoy <chris at lod.com> wrote:
>
>> ive used jquery to do this, where i have a thumbnail and they click to
>> play it.
>>
>>
>> http://blog.pixelthemes.com/demo/load-yt-video-dynamically/
>>
>>
>>
>> On 2013-09-11 7:03 AM, "Steve Taylor" <steve at sltaylor.co.uk> wrote:
>>
>> >Hi folks,
>> >
>> >Does anyone know how to stop the playing of an embedded video (e.g.
>> >YouTube) using JavaScript?
>> >
>> >I'm looking at the YT docs
>> >(https://developers.google.com/youtube/player_parameters) and the WP
>> >core source, but I'm having trouble finding how to target the actual
>> >player object.
>> >
>> >I'm embedding the actual video programmatically, something like this:
>> >
>> >echo wp_oembed_get( $url . '&enablejsapi=1', array( 'width' => 500,
>> >'height' => 362 ) );
>> >
>> >Any pointers welcome!
>> >
>> >Cheers,
>> >
>> >Steve
>> >_______________________________________________
>> >wp-hackers mailing list
>> >wp-hackers at lists.automattic.com
>> >http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>_______________________________________________
>wp-hackers mailing list
>wp-hackers at lists.automattic.com
>http://lists.automattic.com/mailman/listinfo/wp-hackers




More information about the wp-hackers mailing list