Comments (7)
Hi @DrewBourgeois, I just released version 4.1.0 which adds the functionality you need. If you are using ASPVideoPlayer
set the configuration
property with allowBackgroundPlay: true
.
from aspvideoplayer.
Thanks so much!
from aspvideoplayer.
Hi @andreipitis, I'm trying to have the background audio of a video asset controllable through MPRemoteCommandCenter at the lock screen, but it doesn't seem to work as videoPlayerLayer.player = nil
when it enters the background. Do you have any tips on how to make this happen? Thanks!
from aspvideoplayer.
Hi @DrewBourgeois,
The player
object needs to be removed from the videoPlayerLayer
in order to enable background playback. This does not deallocate the player, there is still a strong reference to it and all the functions to control playback should still work.
You should be able to control the playback with methods like playVideo()
, pauseVideo()
if you are using ASPVideoPlayerView
.
If you are using ASPVideoPlayer
you can control playback by accessing the videoPlayerControls
property:
//First method
let controls = videoPlayer.videoPlayerControls as? ASPVideoPlayerControls
controls?.pause()
//Second method
let player = videoPlayer.videoPlayerControls.videoPlayer
player?.pauseVideo()
Did you enable Background Modes for audio playback in Capabilities?
I can only speculate without seeing the actual code.
from aspvideoplayer.
Hi @andreipitis,
Thanks for that!
The command center controls don't control the playback when the app is in the background and videoPlayerLayer.player = nil
is in appDidEnterBackground. The command center controls work fine when the app is in the foreground, or videoPlayerLayer.player = nil
is taken out of appDidEnterBackground and the screen is locked.
The following is in ASPVideoPlayerView:
private func commonInit() {
UIApplication.shared.beginReceivingRemoteControlEvents()
let commandCenter = MPRemoteCommandCenter.shared()
commandCenter.pauseCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
self.pauseVideo()
return .success
}
commandCenter.playCommand.addTarget { (event) -> MPRemoteCommandHandlerStatus in
self.playVideo()
return .success
}
}
My AVAudio session is set to AVAudioSessionCategoryPlayback and background audio capabilities are set.
Thanks!
from aspvideoplayer.
@DrewBourgeois I tried your code and it seems to be working fine in my case. I can put the app in the background while continuing to play audio and I can pause/resume it from command center.
In my case, the MPRemoteCommandCenter
setup was done in a ViewController that had a reference to the player as to not modify the component code. Maybe this change can work for you as well.
UIApplication.shared.beginReceivingRemoteControlEvents()
is not necessary when using MPRemoteCommandCenter
according to the documentation, but if it still doesn't work, you could try moving it in AppDelegate
:
func applicationDidEnterBackground(_ application: UIApplication) {
UIApplication.shared.beginReceivingRemoteControlEvents()
}
from aspvideoplayer.
Hi @andreipitis I got the code working the way I want.
Thanks so much for your help, and also for developing a really great video player!
from aspvideoplayer.
Related Issues (20)
- Controls Visible HOT 2
- rtsp/rtmp support? HOT 2
- Cannot pause when pause button is clicked for audio HOT 2
- Default Font HOT 2
- Show time left instead of length of video HOT 2
- ASPVideoPlayer has no sounds when play video HOT 5
- Property 'self.newVideo' not initialized at super.init call HOT 2
- can not seek video when put in sliding panel HOT 2
- Playing multiple video at same time. HOT 2
- 'CMTime' has no member 'kCMTimeZero' HOT 2
- mp4 video coming from the URL not running HOT 3
- Hi ..How would i know if the view is playing video in ASPVideoPlayerView . HOT 1
- Property 'self.readyToPlayVideo' not initialized at super.init call HOT 3
- How can i delegate didpressednextbutton? HOT 1
- Resize Button Is Outside of View HOT 2
- How to create custom view on video player HOT 1
- Foreground problem HOT 1
- used seekTime - getting small struct HOT 1
- Background Video need to stop. HOT 1
- No playback speed (1.5x,2x,2.5x) adjuster
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aspvideoplayer.