Merge pull request #3211 from mysport12/master
Feature: audioOutput - Play over phone earpiece
This commit is contained in:
@@ -197,7 +197,7 @@ enum RCTPlayerOperations {
|
||||
var options:AVAudioSession.CategoryOptions? = nil
|
||||
|
||||
if (ignoreSilentSwitch == "ignore") {
|
||||
category = AVAudioSession.Category.playback
|
||||
category = AVAudioSession.Category.playAndRecord
|
||||
} else if (ignoreSilentSwitch == "obey") {
|
||||
category = AVAudioSession.Category.ambient
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
private var _controls:Bool = false
|
||||
|
||||
/* Keep track of any modifiers, need to be applied after each play */
|
||||
private var _audioOutput: String = "speaker"
|
||||
private var _volume:Float = 1.0
|
||||
private var _rate:Float = 1.0
|
||||
private var _maxBitRate:Float?
|
||||
@@ -517,6 +518,20 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
applyModifiers()
|
||||
}
|
||||
|
||||
@objc
|
||||
func setAudioOutput(_ audioOutput:String) {
|
||||
_audioOutput = audioOutput
|
||||
do {
|
||||
if audioOutput == "speaker" {
|
||||
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
|
||||
} else if audioOutput == "earpiece" {
|
||||
try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSession.PortOverride.none)
|
||||
}
|
||||
} catch {
|
||||
print("Error occurred: \(error.localizedDescription)")
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
func setVolume(_ volume:Float) {
|
||||
_volume = volume
|
||||
@@ -587,6 +602,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
||||
setMaxBitRate(_maxBitRate)
|
||||
}
|
||||
|
||||
setAudioOutput(_audioOutput)
|
||||
setSelectedAudioTrack(_selectedAudioTrackCriteria)
|
||||
setSelectedTextTrack(_selectedTextTrackCriteria)
|
||||
setResizeMode(_resizeMode)
|
||||
|
@@ -17,6 +17,7 @@ RCT_EXPORT_VIEW_PROPERTY(selectedAudioTrack, NSDictionary);
|
||||
RCT_EXPORT_VIEW_PROPERTY(paused, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(muted, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(controls, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(audioOutput, NSString);
|
||||
RCT_EXPORT_VIEW_PROPERTY(volume, float);
|
||||
RCT_EXPORT_VIEW_PROPERTY(playInBackground, BOOL);
|
||||
RCT_EXPORT_VIEW_PROPERTY(preventsDisplaySleepDuringVideoPlayback, BOOL);
|
||||
|
Reference in New Issue
Block a user