How to play Audio only in a video file in AVPlayer
Make your video player size 0x0 or place it outside of the screen.
AVPlayer audio only works when ringer is on
https://developer.apple.com/documentation/avfoundation/avplayer/1390127-volume
Turns out that the volume is set to 0.0 when ringer is in silent mode. By setting the volume to 1.0 by default, there is volume all the time.
Added this:
self.player?.volume = 1.0
inside of the child view below the videoGravity line
Video is not showing me use AVPlayer only audio is working
I guess that the problem is in your video file. Try to download another video mp4 video sample. Add it to your project and try.
You don't need this code:
self.videoPlayer.view.frame = self.view.frame;
[self.view addSubview:self.videoPlayer.view];
Swift: Playing audio using AVPlayer - Audio is not playing, cannot hear audio
When using AVPlayer you should make sure your device is not on silent mode as that will cause to not output audio even though your volume is at max.
If you would like to keep your device on silent mode and still play the audio you can use the following code before your .play():
do {
try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [])
}
catch {
// report for an error
print(error)
}
Related Topics
Fit Image of Random Size into a Uiwebview (Ios)
Ios: Diddiscoverperipheral Not Called in Background Mode
How to Change Uibutton Image After Clicking in Swift
Enabling Facebook Breaking Changes Feb 2013: Login Does Not Work
Xamarin.iOS Binding Libraries/Native Frameworks
The Proper Way of Doing Chain Animations
Swift Spritekit Facebook Share Button
Add Button at the End of Collection View in Storyboard
How to Save Custom Objects in Array and Store It in Nsuserdefaults - Iphone
How to Resolve iOS Link Errors with Opencv
How to Integrate Payu Money in Swift
Apple Watchkit Simulator Issue: Sperrorinvalidbundlenogizmobinarymessage
How to Set Uibutton Type in Uibutton Subclass
How to Set the Accessibility Label for a Particular Segment of a Uisegmentedcontrol
Is Float, Double, Int an Anyobject