diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index cb89db911f06..2fae7f10cd04 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -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()) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index fb8892f105b9..74d4705a15b4 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -224,6 +224,8 @@ class WebContents : public mate::TrackableObject, const std::vector& 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; diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index d4bf55158fed..335d6516fc37 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -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 diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index b28fec23ed83..04fa707da764 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -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'] diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 90ecda9168be..abb038ac1ab2 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -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: diff --git a/spec/fixtures/assets/LICENSE b/spec/fixtures/assets/LICENSE new file mode 100644 index 000000000000..ec56b38f44ed --- /dev/null +++ b/spec/fixtures/assets/LICENSE @@ -0,0 +1,3 @@ +tone.wav +http://soundbible.com/1815-A-Tone.html +License: Public Domain diff --git a/spec/fixtures/assets/tone.wav b/spec/fixtures/assets/tone.wav new file mode 100644 index 000000000000..7fbc54cbe196 Binary files /dev/null and b/spec/fixtures/assets/tone.wav differ diff --git a/spec/fixtures/pages/audio.html b/spec/fixtures/pages/audio.html new file mode 100644 index 000000000000..0fda8e7075bc --- /dev/null +++ b/spec/fixtures/pages/audio.html @@ -0,0 +1 @@ + diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index c60af8d74d1f..28b25a226617 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -379,3 +379,14 @@ describe ' 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