-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix audio focus #1897
Fix audio focus #1897
Conversation
@@ -580,6 +580,10 @@ private void clearResumePosition() { | |||
public void onAudioFocusChange(int focusChange) { | |||
switch (focusChange) { | |||
case AudioManager.AUDIOFOCUS_LOSS: | |||
eventEmitter.audioFocusChanged(false); | |||
audioManager.abandonAudioFocus(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to abandon focus, should we pause automatically? still giving the user the option to stop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds fine, but my idea was to allow the dev to have full control of order of operations, but could be easily done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Come to think of it, you're right, this is the right way of enforcing good behavior and will require no changes from the devs. Will add it ASAP,t hanks for the feedback!
These changes are available in |
* Fix so background audio from other apps can play when disableFocus is true. requestAudioFocus was being run regardless of there being a src, so I made it so that only gets requested when a src exists. * Added details to readme and changelog * update for androidX * change minSdkVersion back to 16 * update readme * remove duplicate ReactVideoPackage() * add readme to migrating to AndroidX * add read me * fix read me * pre androidX, upgrade to 28 * remove duplicated line in example * change dead code in example * Remove calls to [super observe] to fix crash * Add TheWidlarzGroup#1646 to changelog * bring back super KVO with selector check * Fix memory leak when using AVPlayerViewController, make sure to release player * Updated changelog * changelog for TheWidlarzGroup#1629 * bump version * chang maven to google * fix when controls & muted * update changelog * handle racing conditions when props are setted on exoplayer * fix for setControls * fix repeat * comment why postDelayed * remove extra whitespace * remove rnpm * 4.4.4 * Update README.md Make installation parts easier to link * Update README.md fix typo * Update README.md Make more obvious the changes needed via using diff * Update MainApplication.java fix indent * remove matchingfallbacks in example * prepare 5.0.0 version * cpck androidx * change minSdkVersion back to 16 (cherry picked from commit a96fa33) * update readme (cherry picked from commit 3ddcba3) * add readme to migrating to AndroidX (cherry picked from commit 976ebcc) * cpck readme * fix read me (cherry picked from commit ed25b3f) * chang maven to google (cherry picked from commit 8a8f215) * cpck * ad platform installation to TOC (cherry picked from commit b0737bd) * More update info (cherry picked from commit 2f23cc0) * 5.0.1 * Fixed Exoplayer doesn't work with mute=true TheWidlarzGroup#1696 * Updated README.md to include instructions for React Native 0.60 and above * Removing the call to observeValueForKeyPath:ofObject:change:context: on super from RCTVideo. If the super class is not actually observing the key, the app will crash. Checking to see if the super class responds to this selector doesn't solve this issue. react-native-video github issue: TheWidlarzGroup#1515 Discussion about this particular problem: https://stackoverflow.com/questions/6574714/whats-wrong-with-this-observevalueforkeypathofobjectchangecontext-implement * Updated CHANGELOG to reflect bug fix in PR 1720 * added support for automaticallyWaitsToMinimizeStalling property on iOS * update readme * fix invert boolean property * bumped version & updated changelog * fix formatting issues * fix formatting fix crash iOS9 * changelog for TheWidlarzGroup#1696 * Update issue templates * Update bug_report.md * Update bug_report.md * Fix indent and respect previous rate * Bring the basic example back to a runnable state * Remove Exoplayer deprecations - Bump Exoplayer to 2.10.4 - Remove deprecated usages of Exoplayer methdos - Add `ReactExoplayerConfig` as extension points to configure the Exoplayer instance * Update changelog with Exoplayer update (TheWidlarzGroup#1766) * update package json version * update changelog version * Add disableFocus to TOC * fix typo in README * Clear progress messages on STATE_IDLE and STATE_BUFFERING (TheWidlarzGroup#1768) The progress message handler will duplicate recursions of the `onProgressMessage` handler on change of player state from any state to STATE_READY with `playWhenReady` is true (when video is not paused). This clears the messages on STATE_IDLE and STATE_BUFFERING to break the recursion. * fix README about reportBandwidth (TheWidlarzGroup#1816) * Fixes a situation when exiting fullscreen, where observed keypath values have not been released * add try catch block around removal of observer keypaths on playerViewController * Audio Poster issue fix (TheWidlarzGroup#1779) * Add full screen support to Android Exoplayer (TheWidlarzGroup#1730) * Bump version to 5.1.0-alpha * Fix readme grammar (TheWidlarzGroup#1888) * Improve Android Audio Focus (TheWidlarzGroup#1897) Implement audio focus as per android docs: https://developer.android.com/guide/topics/media-apps/audio-focus https://medium.com/androiddevelopers/audio-focus-3-cdc09da9c122 AUDIOFOCUS_LOSS should abandon focus and not try resuming audio, this is done with AUDIOFOCUS_LOSS_TRANSIENT This fixes at least: - Audio not being paused after focus being taken by some voip applications - Content resuming and pausing instantly sporadically (some race condition perhaps) when activity was resumed from background. * Update changelog (TheWidlarzGroup#1913) * docs(video): fix bufferConfig property name (TheWidlarzGroup#1855) * Fix play/pause regression after added fullscreen support. (TheWidlarzGroup#1916) * v5.1.0-alpha4 * Bump javascript dependencies (TheWidlarzGroup#1914) Also update linting rules to match other community repositories. * Add support for react-native Windows Cpp/WinRT (TheWidlarzGroup#1893) This also deprecates the old react-native windows implementation * Fix the `ref` sample code to remove the syntax error * Update changelog * v5.1.0-alpha5 * Don't set reactViewController view frame to whole screen (TheWidlarzGroup#1931) this fixes the case on any time you have a react view that displays the video, but it's being rendered with controls but not as a full screen (ie. easily reproducible when you have a tabbar for instance - the reactViewController.view frame shouldnt be the whole screen bounds). * Update onLoad event to include videoTracks info * add mixWithOthers prop * Update README.md * Update index.ios.js * Fix video dimensions for HLS streams * Changelog * Compare CGFloats instead * Update CHANGELOG.md * Update CHANGELOG, alpha-6 hasn't been released yet * Implement pending seek * Recommend npx pod-install for setup instructions # Summary We've been recommending devs use `npx pod-install` since it will attempt to install CocoaPods CLI if it's not available on the computer (cite [React Navigation setup guide](https://reactnavigation.org/docs/getting-started/#installing-dependencies-into-a-bare-react-native-project)). This has proved very useful for Expo users who are now migrating to the bare workflow and want to use community packages in their projects. ## Checklist - [x] I have tested this on a device and a simulator - [x] I added the documentation in `README.md` * Expose currentPlaybackTime when live stream video (TheWidlarzGroup#1944) * added trackId to exoplayer onLoad callback * added trackInfo to bandwidth callback * syntax fix * syntax fix * version update * sending complete logcat for media playback exception ExoPlaybackException * version bump * package publish changes * Live playback fix * Version bump * import fix * version bump * configurable preferredForwardBufferDuration * configurable preferredForwardBufferDuration * version update * Exposing time * exo player window current tsp * return type * Current window timestamp in epoch * iOS changes * version update * Updated package.json * updated version * CurrentTime bug fix * Updated package.json * Updated currentPlaybackTime * Updated currentPlayback logic * Updated package.json * Bug fix * Added semicolon * updated package.json * Updated ReactVideoView * updated verison * Revert package.json changes * Update ReactVideoView.java * Use standard log * Document preferredForwardBufferDuration (iOS) * Document currentPlaybackTime * Document trackId * Update CHANGELOG.md * Update CHANGELOG.md * Update README.md * Update CHANGELOG.md Co-authored-by: anubansal <anu.bansal@curefit.com> Co-authored-by: Sivakumar J <sivakumar@curefit.com> Co-authored-by: parikshit <parikshit@curefit.com> Co-authored-by: anubansal92 <40559524+anubansal92@users.noreply.github.com> Co-authored-by: Rishu Agrawal <rishu.agrawal@v.curefit.com> Co-authored-by: rishu-curefit <54575330+rishu-curefit@users.noreply.github.com> * [ios] Adaptive fullscreen in landscape by device orientation (TheWidlarzGroup#1862) * update UIInterfaceOrientation in fullscreen * update code * Revert "[ios] Adaptive fullscreen in landscape by device orientation (TheWidlarzGroup#1862)" (TheWidlarzGroup#2043) This reverts commit c9096d1. * Upgrade exoplayer to 2.11.4 (TheWidlarzGroup#2034) * Removed JS fullscreening for Android (TheWidlarzGroup#2013) * Always set headers for iOS (TheWidlarzGroup#2014) * Support preventsDisplaySleepDuringVideoPlayback (TheWidlarzGroup#2019) * Add flag on iOS * Add flag in Android * Add documentation * Add changelog entry * Also set setKeepScreenOn * Fix prop not being set * add preventsDisplaySleepDuringVideoPlayback to exoplayer * Update android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java * Update android-exoplayer/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java Co-authored-by: Jens Andersson <jens@fritan.com> Co-authored-by: Anton Tanderup <antontandrup@gmail.com> Co-authored-by: Jens Andersson <jens@fritan.com> * Fix exoplayer aspect ratio update on source changes (TheWidlarzGroup#2053) * Fix exoplayer aspect ratio update on source changes * Update CHANGELOG.md * Add iOS and Android basic DRM support (TheWidlarzGroup#1445) This PR adds support for DRM streams on iOS (Fairplay) and Android (Playready, Widevine, Clearkey) I am neither Android nor iOS developer, so feel free to provide feedback to improve this PR. **Test stream for ANDROID:** ``` testStream = { uri: 'http://profficialsite.origin.mediaservices.windows.net/c51358ea-9a5e-4322-8951-897d640fdfd7/tearsofsteel_4k.ism/manifest(format=mpd-time-csf)', type: 'mpd', drm: { type: DRMType.PLAYREADY, licenseServer: 'http://test.playready.microsoft.com/service/rightsmanager.asmx?cfg=(persist:false,sl:150)' } }; ``` or ``` { uri: 'https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p.mpd', drm: { type: 'widevine', //or DRMType.WIDEVINE licenseServer: 'https://drm-widevine-licensing.axtest.net/AcquireLicense', headers: { 'X-AxDRM-Message': 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2ZXJzaW9uIjoxLCJjb21fa2V5X2lkIjoiYjMzNjRlYjUtNTFmNi00YWUzLThjOTgtMzNjZWQ1ZTMxYzc4IiwibWVzc2FnZSI6eyJ0eXBlIjoiZW50aXRsZW1lbnRfbWVzc2FnZSIsImZpcnN0X3BsYXlfZXhwaXJhdGlvbiI6NjAsInBsYXlyZWFkeSI6eyJyZWFsX3RpbWVfZXhwaXJhdGlvbiI6dHJ1ZX0sImtleXMiOlt7ImlkIjoiOWViNDA1MGQtZTQ0Yi00ODAyLTkzMmUtMjdkNzUwODNlMjY2IiwiZW5jcnlwdGVkX2tleSI6ImxLM09qSExZVzI0Y3Iya3RSNzRmbnc9PSJ9XX19.FAbIiPxX8BHi9RwfzD7Yn-wugU19ghrkBFKsaCPrZmU' }, } } ``` **Test stream for iOS:** Sorry but I can not provide free streams to test. If anyone can provide test streams, or found some we can use, please let me know to also test them. It has been tested with a private provider and they work, at least with the `getLicense` override method. (An example implementation is provided in the README) * Ready 5.1.0-alpha6 for release * Prepare 5.1.0-alpha7 * Port over fix from 4.x branch * Prepare 5.1.0-alpha8 * Bugfix: TheWidlarzGroup#1930 * Add ARM64 support for windows (TheWidlarzGroup#2137) Adding arm64 support for RNW builds. Nothing in this project is using anything that isn't already supported in arm64 windows libs. It was simply overlooked when RNW was originally added. We have been using RNW and RNV in our project for 6+ months and just been using a patch-package to apply this change. Figured it was overdue to upstream this change. You can see this similar code in the RNW repo. https://github.com/microsoft/react-native-windows/blob/95935e008621778dbcec01363602c19abc060632/packages/microsoft-reactnative-sampleapps/windows/SampleLibraryCPP/SampleLibraryCPP.vcxproj#L28 and https://github.com/microsoft/react-native-windows/blob/master/packages/microsoft-reactnative-sampleapps/windows/SampleLibraryCPP/SampleLibraryCPP.vcxproj#L44 * Update README.md (TheWidlarzGroup#2076) You only need to perform linking for React Native < 0.60 * fix: Xcode 12 compatibility (TheWidlarzGroup#2152) Latest Xcode 12 fails to build while without a module to depend on React-Core directly hence this change is necessary for native modules on iOS. This change requires to React Native 0.60.2 or newer. For more details please check: facebook/react-native#29633 (comment) * Renaming Boolean etc to AsBoolean (TheWidlarzGroup#2119) * Resolved an issue where setting a video to paused would ignore the “silent switch” setting * iOS DRM Fixes for License Fetching (TheWidlarzGroup#2208) * Update package.json version number to 5.1.1 * Update ReactNativeVideoCPP.vcxproj (TheWidlarzGroup#2288) * Exoplayer: Use okhttp version specified in gradle.properties (TheWidlarzGroup#2340) Because React Native uses okhttp, including exoplayer causes apps to use two different versions of okhttp. This results in some unpredictable behavior. Clients of `react-native-video` should be able to specify the same OKHTTP version to react-native and react-native video. See where it's specified in react-native trunk: - https://github.com/facebook/react-native/blob/master/ReactAndroid/gradle.properties#L15 - https://github.com/facebook/react-native/blob/e1b6cd3f756aa034b11af6bf9960efb42bde8692/ReactAndroid/build.gradle#L452-L453 * React Native Windows updates (TheWidlarzGroup#2206) Various updates for React Native Windows **Docs** * Fixed windows installation in readme * Added local dev setup instructions **Build** * Added VS solutions for RNW 0.61, 0.62, and 0.63+ * Added clang-formatting definition **Features** * Fixed autolinking for RNW 0.63+ * Added support for `rate` property **Examples** * Upgraded examples/basic to RN 0.61 and replaced broken windows app * Update README.md (TheWidlarzGroup#2292) Fix broken link for ignoresilentswitch * Fix AudoFocus pausing video when attempting to play (TheWidlarzGroup#2311) Fix AudioFocus bug that could cause the player to stop responding to play/pause in some instances. Fixes issue TheWidlarzGroup#1945 This was caused by the player requesting audio focus on each play (un-pause) and that resulted in a small window of Audio focus loss and then gain. The focus loss results in the player being paused while the player was supposed to play at the time. The solution is to keep track of Audio focus and not request new focus if we already have it. * Upgrade ExoPlayer to 2.13.2 (TheWidlarzGroup#2317) Upgrade ExoPlayer from 2.11.4 to 2.13.2 and fix any issues related to the upgrade and deprecated method use. * update exoplayer to allow pre-init and content clear * Fix for tvOS native audio menu language selector * Release 5.2.0-alpha1 * Typo * Release 5.2.0 * Use prop types from `deprecated-react-native-prop-types` Starting with React Native 0.68, using Prop Types from `react-native` emits a warning. * Update Video.js Co-authored-by: Elliott Kember <elliott.kember@gmail.com> # Conflicts: # Video.js * Replace Image.propTypes with ImagePropTypes. # Conflicts: # Video.js * fix(Exoplayer): fix exoplayer version tà 2.13.3 * chore: fix build without exoplayer * v5.2.1 * docs: update Android installation * * removed duplicate method * * fix onRemotePlayPause in android * * remove duplicate code * * fix cannot find symbol after RN update --------- Co-authored-by: Kurt Johnson <kurt.johnson@lightmaker.com> Co-authored-by: Kurt Johnson <kurtjohnson8@gmail.com> Co-authored-by: vok <admin@MacOnes-MacBook-Pro-2.local> Co-authored-by: Zaid Daghestani <zaid.daghestani@gmail.com> Co-authored-by: Jens Andersson <jens@fritan.com> Co-authored-by: Daniel Mariño Ruiz <1237997+CHaNGeTe@users.noreply.github.com> Co-authored-by: Daniel Mariño <daniel.marino@24imedia.com> Co-authored-by: Ash Mishra <a.mishra@nfb.ca> Co-authored-by: Andrew Chae <asjchae@gmail.com> Co-authored-by: Jamie Halvorson <jamie@halvorson.co.uk> Co-authored-by: Nahuel Marisi <nahuel.marisi@klarna.com> Co-authored-by: Jovan Stanimirovic <jovan@netlog.com> Co-authored-by: Benoit Dion <unknown> Co-authored-by: Benoit Dion <573574+benoitdion@users.noreply.github.com> Co-authored-by: Bader Serhan <baderserhan@gmail.com> Co-authored-by: Tsukasa Setoguchi <tsukasa.setoguchi@gmail.com> Co-authored-by: Learnyst <shankar@karaokegarage.com> Co-authored-by: IbrahimSulai <33604125+IbrahimSulai@users.noreply.github.com> Co-authored-by: Benoit Dion <benoit@eliteness.app> Co-authored-by: Mohammed Salman <msal4@outlook.com> Co-authored-by: Michael Tintiuc <michaeltintiuc@users.noreply.github.com> Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com> Co-authored-by: Benoit Dion <benoitdion@gmail.com> Co-authored-by: Di Da <dida@microsoft.com> Co-authored-by: Brandon Faulkner <college.bfaulk96@yahoo.com> Co-authored-by: Marlon Andrade <marlonmandrade@gmail.com> Co-authored-by: Hampton Maxwell <me@hamptonmaxwell.com> Co-authored-by: Harrison Mendonça <harrisonmendonca@gmail.com> Co-authored-by: Evan Bacon <baconbrix@gmail.com> Co-authored-by: Param Aggarwal <paramaggarwal@gmail.com> Co-authored-by: anubansal <anu.bansal@curefit.com> Co-authored-by: Sivakumar J <sivakumar@curefit.com> Co-authored-by: parikshit <parikshit@curefit.com> Co-authored-by: anubansal92 <40559524+anubansal92@users.noreply.github.com> Co-authored-by: Rishu Agrawal <rishu.agrawal@v.curefit.com> Co-authored-by: rishu-curefit <54575330+rishu-curefit@users.noreply.github.com> Co-authored-by: Tuan Luong <tuanluong.it@gmail.com> Co-authored-by: limaAniceto <lima.aniceto@gmail.com> Co-authored-by: Anders Lemke <mail@anderslemke.dk> Co-authored-by: Anton Tanderup <antontandrup@gmail.com> Co-authored-by: Jeferson Daniel <contato@jefersondaniel.com> Co-authored-by: Daniel Mariño <35027703+danielmarino24i@users.noreply.github.com> Co-authored-by: Hampton Maxwell <hmaxwell@ellation.com> Co-authored-by: Nick Fujita <nickfujita@gmail.com> Co-authored-by: redspear <willkoia@gmail.com> Co-authored-by: Adam Gorman <namrog84@users.noreply.github.com> Co-authored-by: Irwin <irwinwilliams@users.noreply.github.com> Co-authored-by: Radek Czemerys <7029942+radko93@users.noreply.github.com> Co-authored-by: Tero Paananen <54746036+tero-paananen@users.noreply.github.com> Co-authored-by: Cameron Perry <cameron.perry@valtech.com> Co-authored-by: Alexander Sklar <asklar@microsoft.com> Co-authored-by: Sean Holbert <sdholbs@gmail.com> Co-authored-by: Jon Thysell <thysell@gmail.com> Co-authored-by: Milan Susnjar <milanrs@gmail.com> Co-authored-by: Armands Malejev <armands.malejevs@gmail.com> Co-authored-by: Jonas Dalesjö <jonas.dalesjo@gmail.com> Co-authored-by: Shane Mckenna <shanemckennadev@gmail.com> Co-authored-by: Renaud Chaput <renchap@gmail.com> Co-authored-by: olivier bouillet <olivier.bouillet@ifeelsmart.com> Co-authored-by: Omar Diop <accounts@omardiop.com> Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Co-authored-by: ARTSOFT\csillaj <jenei_csilla@yahoo.com>
Implement audio focus as per android docs:
https://developer.android.com/guide/topics/media-apps/audio-focus
https://medium.com/androiddevelopers/audio-focus-3-cdc09da9c122
AUDIOFOCUS_LOSS
should abandon focus and not try resuming audio, this is done withAUDIOFOCUS_LOSS_TRANSIENT
This fixes at least:
Since this is triggering events, my proposal is to trigger the same event as for
AUDIO_FOCUS_LOSS
and let the developer choose to either use stop or pause, yet we explicitly abandon focus as per the docs.