restarting soung that keeps background active (#13)

This commit is contained in:
Gustavo Emanuel Farias Rosa 2022-06-16 10:44:18 -03:00 committed by GitHub
parent abd7254b30
commit 569bfe98ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,7 @@ class ScreenShareServiceManager: NSObject {
var audioSession = AVAudioSession.sharedInstance()
var player: AVAudioPlayer!
@objc func stopScreenShareBroadcastExtension() -> Void {
BBBSharedData
.getUserDefaults(appGroupName: BigBlueButtonSDK.getAppGroupName())
@ -25,28 +26,23 @@ class ScreenShareServiceManager: NSObject {
// React native exposed method (called when user click the button to share screen)
@objc func initializeScreenShare() -> Void {
logger.info("initializeScreenShare")
self.activeAudioSession(bool: true)
Task.init {
do{
try audioSession.setActive(true)
}catch{
print(error)
}
let path = Bundle.main.path(forResource: "music2", ofType : "mp3")!
let url = URL(fileURLWithPath : path)
print("audioUrl2 = \(url)")
do {
let path = Bundle.main.path(forResource: "music2", ofType : "mp3")!
let url = URL(fileURLWithPath : path)
print("audioUrl2 = \(url)")
do {
player = try AVAudioPlayer(contentsOf: url)
player.play()
}
catch {
print (error)
}
self.player = try AVAudioPlayer(contentsOf: url)
self.player.play()
self.playSoundInLoop()
}
catch {
logger.error("Error to play audio = \(url)")
}
// Request the system broadcast
logger.info("initializeScreenShare - requesting broadcast")
SystemBroadcastPicker.requestBroadcast()
@ -97,4 +93,23 @@ class ScreenShareServiceManager: NSObject {
}
func activeAudioSession(bool BoolToActive: Bool){
do{
try audioSession.setActive(BoolToActive)
}catch{
logger.error("Error to change status of audioSession")
}
}
//This method prevents the sound that keeps the app active in the background
func playSoundInLoop(){
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 3000) {
self.logger.info("restarting music")
self.player.currentTime = 0.1;
self.playSoundInLoop()//recursive call
}
}
}