Add media play events to webview

This commit is contained in:
Brian R. Bondy 2015-12-19 22:16:22 -05:00
parent bff2861311
commit fed0c43970
9 changed files with 38 additions and 1 deletions

View file

@ -452,6 +452,14 @@ void WebContents::PluginCrashed(const base::FilePath& plugin_path,
Emit("plugin-crashed", info.name, info.version);
}
void WebContents::MediaStartedPlaying() {
Emit("media-started-playing");
}
void WebContents::MediaPaused() {
Emit("media-paused");
}
void WebContents::DocumentLoadedInFrame(
content::RenderFrameHost* render_frame_host) {
if (!render_frame_host->GetParent())

View file

@ -224,6 +224,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
const std::vector<content::FaviconURL>& urls) override;
void PluginCrashed(const base::FilePath& plugin_path,
base::ProcessId plugin_pid) override;
void MediaStartedPlaying() override;
void MediaPaused() override;
// brightray::InspectableWebContentsViewDelegate:
void DevToolsFocused() override;

View file

@ -22,7 +22,9 @@ supportedWebViewEvents = [
'page-title-updated'
'page-favicon-updated'
'enter-html-full-screen'
'leave-html-full-screen'
'leave-html-full-screen',
'media-started-playing',
'media-paused',
]
nextInstanceId = 0

View file

@ -20,6 +20,8 @@ WEB_VIEW_EVENTS =
'crashed': []
'gpu-crashed': []
'plugin-crashed': ['name', 'version']
'media-started-playing': []
'media-paused': []
'destroyed': []
'page-title-updated': ['title', 'explicitSet']
'page-favicon-updated': ['favicons']

View file

@ -221,6 +221,14 @@ Emitted when `webContents` wants to do basic auth.
The usage is the same with [the `login` event of `app`](app.md#event-login).
### Event: 'media-started-playing'
Emitted when media starts playing.
### Event: 'media-paused'
Emitted when media is paused or done playing.
## Instance Methods
The `webContents` object has the following instance methods:

3
spec/fixtures/assets/LICENSE vendored Normal file
View file

@ -0,0 +1,3 @@
tone.wav
http://soundbible.com/1815-A-Tone.html
License: Public Domain

BIN
spec/fixtures/assets/tone.wav vendored Normal file

Binary file not shown.

1
spec/fixtures/pages/audio.html vendored Normal file
View file

@ -0,0 +1 @@
<audio autoplay muted src="../assets/tone.wav"></audio>

View file

@ -379,3 +379,14 @@ describe '<webview> tag', ->
webview.src = "file://#{fixtures}/pages/onmouseup.html"
webview.setAttribute 'nodeintegration', 'on'
document.body.appendChild webview
describe 'media-started-playing media-paused events', ->
it 'emits when audio starts and stops playing', (done) ->
audioPlayed = false
webview.addEventListener 'media-started-playing', ->
audioPlayed = true
webview.addEventListener 'media-paused', ->
assert audioPlayed
done()
webview.src = "file://#{fixtures}/pages/audio.html"
document.body.appendChild webview