MagicMirror² v2.13.0 is available! For more information about this release, check out this topic.

Youtube Embed API

  • Hi, I’m fairly new to javascript and really don’t understand how the structure works.

    Is it possible to create a module which uses the Youtube embed API?

    Ultimately i would like to be able to use the remote control to send a notification to play a playlist (from a specified list) from a random point in shuffle mode, as well as being able to pause/play and maybe rewind/repeat he current song.


  • @Stubbsy1994 LMGTFY (or in this case: let me use search function of this forum for you): searching for “embed youtube” on this forum gives this thread. I guess this is what you need.

  • I checked that module, it doesn’t use the youtube API, just a generic iFrame. So it cannot e.g. skip, next, volume, shuffle etc.

  • @Stubbsy1994 The link you provided describes how to embed youtube API into HTML sites using iframe-Tags in two ways. It seems, the module shown in the thread above uses the first method (iframe with source http:// com/embed/VIDEO_ID?parameters). I guess, the pure JS method ultimatively also uses an iframe since its called IFrame Player API.

    As far as I can see, both have equal functionality. It’s not really documented, but it seems like you can call all the functions for the player-object listed here in the direct iframe approach (first method), too. See parameter enablejsapi=1. For example pause or seek-to (not verified for all functions!):

    $('#video1')[0].contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
    $('#video1')[0].contentWindow.postMessage('{"event":"command","func":"seekTo","args":[20, true]}', '*');

    Compare sendCommand function in youtube.js of the module described in the thread above.

    So even though the module may not satisfy all your needs by now, maybe you can take it as a starting point to develop your own solution?!

Log in to reply