nw.js icon indicating copy to clipboard operation
nw.js copied to clipboard

Embedding YouTube video.

Open vlakarados opened this issue 12 years ago • 31 comments

I have difficulties playing an embedded video, the error I get is An error occurred, please try again later.. This error is shown after clicking the "play" button on the video. One more thing is that the video background (the preview image) is completely black too.

Here's the console log:

[28334:0903/093637:INFO:CONSOLE(0)] "XMLHttpRequest cannot load chrome-extension://boadgeojelhgndaghljhdicfkmllpafd/cast_sender.js. Cross origin requests are only supported for HTTP.", source: https://www.youtube.com/embed/undefined?html5=0 (0)
[28334:0903/093637:INFO:CONSOLE(0)] "XMLHttpRequest cannot load chrome-extension://dliochdbjfkdbacpmhlcpmleaejidimm/cast_sender.js. Cross origin requests are only supported for HTTP.", source: https://www.youtube.com/embed/undefined?html5=0 (0)
[28334:0903/093637:INFO:CONSOLE(0)] "XMLHttpRequest cannot load chrome-extension://hfaagokkkhdbgiakmmlclaapfelnkoah/cast_sender.js. Cross origin requests are only supported for HTTP.", source: https://www.youtube.com/embed/undefined?html5=0 (0)
[28334:0903/093637:INFO:CONSOLE(0)] "XMLHttpRequest cannot load chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js. Cross origin requests are only supported for HTTP.", source: https://www.youtube.com/embed/undefined?html5=0 (0)
[28334:0903/093637:INFO:CONSOLE(0)] "XMLHttpRequest cannot load chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js. Cross origin requests are only supported for HTTP.", source: https://www.youtube.com/embed/undefined?html5=0 (0)
[28334:0903/093637:INFO:CONSOLE(184)] "Uncaught ReferenceError: chrome is not defined", source: https://s.ytimg.com/yts/jsbin/www-embed-player-vflhH34Cp/www-embed-player.js (184)
[28334:0903/093637:INFO:CONSOLE(140)] "Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'chrome-extension://enhhojjnijigcajfphajepfemndkmdlo/cast_sender.js'.", source: https://s.ytimg.com/yts/jsbin/www-embed-player-vflhH34Cp/www-embed-player.js (140)

What is this chrome-extension://.../cast_sender.js? Is it the root of the problem?

Related question on SO: http://stackoverflow.com/questions/25622310/node-webkit-and-youtube-chrome-is-not-defined.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

vlakarados avatar Sep 03 '14 06:09 vlakarados

Hm, after I have added "user-agent": " Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405", in package.json the errors disappeared, but the video still shows this error message. What can be the problem?

vlakarados avatar Sep 03 '14 07:09 vlakarados

I've tested this on Mac OS X 10.10 with node-webkit 0.10.3 and I didn't have any issues.

How are you embedding the video?I'm using the JavaScript API!

octalmage avatar Sep 04 '14 22:09 octalmage

I have the same issue, I embed the video like this:

<iframe src="http://www.youtube.com/embed/rjKRQYmi1Lk" frameborder="0" allowfullscreen></iframe>

dpalou avatar Sep 05 '14 09:09 dpalou

Like this:

var f = '<iframe width="640" height="480" src="http://www.youtube.com/embed/' + $(this).data('videoId') + '" frameborder="0" allowfullscreen></iframe>';

What are the options for debugging this further?

vlakarados avatar Sep 05 '14 10:09 vlakarados

It seems like this is related to the Chromecast Chrome plugin. I'm assuming you have

"webkit": {
    "plugin": true
  }

in your manifest for flash, so the Chromecast plugin is also getting loaded. Then when it tries to interact with the YouTube player it fails.

Try removing the Chromecast plugin to see if this resolves the issue. if so then your options are:

  1. Remove the Chromecast plugin, there isn't a way to only load specific plugins in node-webkit that I'm aware of. This may not be the best solution especially if you are distributing your app.

  2. Use another method to load the YouTube video. I use the JavaScript Player API and I don't have any issues. You can find my example here:

    https://gist.github.com/octalmage/03a054bb27d597a9f095

    And the API reference:

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

  3. Load your HTML over a webserver. This error seems to be caused by using the file:// protocol so loading your HTML using a local webserver might resolve the issue. I personally use this with method 2 to get past the restricted playback errors.

Hope this helps!

Edit: I just realized I get this error with webkit plugin set to false, try setting it to true! The video works for me without any changes when webkit plugin is enabled. The error does flash before the video plays though.

octalmage avatar Sep 05 '14 12:09 octalmage

Sorry, but I have

"webkit": {
    "plugin": true
}

I tried turning it off and still get the same error as if this option did nothing at all. I also tried setting "chromium-args": "--disable-web-security", but it didn't help.

I will try to use the JavaScript player API on monday to see if it works.

vlakarados avatar Sep 05 '14 13:09 vlakarados

octalmage's solution (in the Edit note) worked for me in Mac OS X, but it doesn't work in Windows XP or Ubuntu 14.04.

dpalou avatar Sep 09 '14 15:09 dpalou

Try the JavaScript technique! It will also give you greater control over the videos.

octalmage avatar Sep 10 '14 01:09 octalmage

@octalmage I tried the player API technique but it's not working for me. I used your exact example. It works fine in a browser, but doesn't even display the videos in my nwjs exe.

When I embed the video in an object or iframe, the correct video appears, but I get an error when I actually try to play it.

Any ideas as to what might be going on here?

My stack question: http://stackoverflow.com/questions/28972140/embedding-youtube-videos-not-working-with-node-webkit

moranm6 avatar Mar 12 '15 13:03 moranm6

@moranm6 what version of nw.js are you using? Are there any errors in the JavaScript console?

octalmage avatar Mar 12 '15 13:03 octalmage

@octalmage Thanks for reaching out!

I'm using nwjs-v0.12.0-win-ia32.

No errors in console (just the loading log). Here's what I see with your code: http://i.imgur.com/u4wiOil.png

As you can see, just the iframe video shows up (nothing displays in the 'ytapiplayer' div), but I get an error when I click to play it.

Thanks again, let me know if you have any ideas!

moranm6 avatar Mar 12 '15 14:03 moranm6

@octalmage In what version of nw.js were you able to get this video to work? I'll try to replicate it.

moranm6 avatar Mar 13 '15 15:03 moranm6

I can reproduce this too (on multiple Mac versions using NW.js 0.13.2), but it only happens for some videos. Embedding https://www.youtube.com/watch?v=cwXfv25xJUw is fine but https://www.youtube.com/watch?v=awVNGfmCQsg doesn't play. It seems to be the format/encoding of the video. Look at how the requests differ:

Success:

screen shot 2016-03-29 at 17 53 59

There are a load of webm requests...

Fails:

screen shot 2016-03-29 at 17 54 18

Just one MP4 request.

So MP4s seem to fail. I've testing with a lot of different video formats/encoding (i.e. uploading videos to youtube and embedding them), including MP4, which worked. So it must be something about the video that I don't know about which is different to the ones I made.

I've tried adding this:

"webkit": {
    "plugin": true
}

ffmpegsumo.so is there. I've tried passing these flags to Chromium with no luck:

"chromium-args": "--enable-decoder=pcm_u8,pcm_s16le,pcm_s24le,pcm_s32le,pcm_f32le,pcm_s16be,pcm_s24be,pcm_mulaw,pcm_alaw,aac,h264,mp3,mpeg4 --enable-demuxer=ogg,matroska,wav,aac,mp3,mov,avi,vorbis --enable-parser=aac,h264,mpegaudio,opus,vorbis"

I have no plugins (Chromecast or otherwise) or anything weird like that, just regular NW.js.


There's a ZIP attached containing a simple package.json and index.html to reproduce. blah.zip.

adam-lynch avatar Mar 29 '16 17:03 adam-lynch

This should be working with latest version now.

In 0.13 we changed to an optimized architecture so more features can be supported, see http://nwjs.io/blog/whats-new-in-0.13/ and it's good for keeping up with Chromium upstream -- we released with Node.js v6.0 and new Chromium versions within 1 day after upstream release.

The new version would fixed many issues reported here and we're scrubbing them. This issue is closed as we believe it should be fixed. Please leave a message if it isn't and we'll reopen it.

nwjs-bot avatar Jul 12 '16 00:07 nwjs-bot

Reopening after I tried embedding a 4 hour old YouTube video and saw this:

screen shot 2016-07-30 at 21 07 38

adam-lynch avatar Jul 30 '16 20:07 adam-lynch

Could you send a minimal app to reproduce? Did you use original ffmpeg provided by NW?

Adam Lynch [email protected]于2016年7月31日周日 04:08写道:

Reopened #2291 https://github.com/nwjs/nw.js/issues/2291.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/nwjs/nw.js/issues/2291#event-740093847, or mute the thread https://github.com/notifications/unsubscribe-auth/AAczeJ-d97HLYCHtk3HVc-Ip9bPeKScnks5qa69agaJpZM4Cd2no .

ghostoy avatar Jul 30 '16 21:07 ghostoy

@ghostoy that's the 0.16.0 SDK download from the site but I opened devtools and used the elements tab to stick in an youtube embed iframe (it's only reproducible with recently uploaded videos I think).

adam-lynch avatar Jul 30 '16 21:07 adam-lynch

@adam-lynch, @ghostoy: I've noticed this as well with some YouTube videos. I solved it by replacing the shipped ffmpeg with a more capable version. I typically replace ffmpeg with the one that ships with Electron and it solves the playback issues (like this one) that I've come across.

frankhale avatar Jul 30 '16 22:07 frankhale

@frankhale can you please describe what you do step by step? For Windows and OS X.

adam-lynch avatar Jul 30 '16 22:07 adam-lynch

I've noticed issues with YouTube playback just like what you described since my app is a YouTube player I am very sensitive to playback issues. What I do is very simple, I download the latest version of Electron and replace NW.js's ffmpeg.dll with the one from Electron. This has solved the problem (just as you described above in your screenshot) for me.

frankhale avatar Jul 30 '16 22:07 frankhale