Hammerspoon / hammerspoon

Staggeringly powerful macOS desktop automation with Lua
http://www.hammerspoon.org
MIT License
12.01k stars 583 forks source link

Can the hs.webview display local videos? #1421

Open Ninlives opened 7 years ago

Ninlives commented 7 years ago

Well I just want to make something like a dynamic wallpaper and I tried to use hs.webview, these html can play local videos in Safari

  <html>
  <video src="/path/to/local/video" id="vi" autoplay="autoplay"></video>
  </html>

but in hs,webview the video didn't show up. Is there any way to do this?

latenitefilms commented 7 years ago

You could try this?

https://github.com/Hammerspoon/hammerspoon/issues/1236#issuecomment-289650836

Ninlives commented 7 years ago

It works but the display feels laggy, and It eats a lot of CPU, maybe Hammerspoon is not good at this kind of task.:) Anyway, thanks!

asmagill commented 7 years ago

I experimented with a module for the AVPlayerView object a while back as an additional type for a canvas... trying to tie the two together I ran into a number of issues that would require a complete rethinking of how Hammerspoon handles view objects, so I kind of put it on hold. However, if there is interest, I think I could have an independent AVPlayerView module available in a few days... it wouldn't integrate with canvas and would be in its own window (though like webview, I'd add methods to choose the window decorations, resizability, etc.)

Ninlives commented 7 years ago

@asmagill Thanks for the quick response :) And I found it weird that the display is not laggy actually, it's because I turn off the sound then it will pause a while after a few seconds then continue playing..if I turn on the sound it works great, is this a bug?

asmagill commented 7 years ago

No clue... Does that seem to make a difference when you play it through Safari? (or another web browser, but Safari is probably going to be the closest comparison to the WKWebView object we use since they're both provided by Apple and both WebKit based)

A completely off-the-top-of-my-head-no-real-evidence-to-support-it theory might be that turning audio off changes the playback buffer cache size and since Hammerspoon does 90%+ of its work on the main thread in the main queue the new cache isn't big enough... but this doesn't get us any closer to a fix since WKWebview doesn't allow us to modify cache sizes and if it's a plugin handling the playback, we have even less control, so...

I'm going to see if I can resurrect my avplayer module this weekend and maybe we can see if it fairs any better.

Ninlives commented 7 years ago

Works fine in Safari.

asmagill commented 7 years ago

If you want to take a look at an avplayer module, check out https://github.com/asmagill/hammerspoon_asm/tree/master/avplayer

I've not had the chance to test it beyond loading a local file and playing it, so if you do use it, please let me know if you run into anything that doesn't work as expected.