Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 31 additions & 12 deletions darwin/Classes/Music.swift
Original file line number Diff line number Diff line change
Expand Up @@ -514,17 +514,6 @@ public class Player : NSObject, AVAudioPlayerDelegate {
print("displayNotification " + displayNotification.description)
print("url: " + url.absoluteString)

/* set session category and mode with options */
if #available(iOS 10.0, *) {
//try AVAudioSession.sharedInstance().setCategory(category, mode: mode, options: [.mixWithOthers])
try AVAudioSession.sharedInstance().setCategory(category, mode: .default, options: [])
try AVAudioSession.sharedInstance().setActive(true)
} else {

try AVAudioSession.sharedInstance().setCategory(category)
try AVAudioSession.sharedInstance().setActive(true)

}
#endif

var item : SlowMoPlayerItem
Expand Down Expand Up @@ -567,7 +556,13 @@ public class Player : NSObject, AVAudioPlayerDelegate {
self.setBuffering(true)
self.isLiveStream = false
observerStatus.append( item.observe(\.status, changeHandler: { [weak self] (item, value) in

//don't execute readyToPlay again when coming back from foreground to avoid re-playing of audio due to line #603
if(self?.currentStatus != .readyToPlay) {
self?.currentStatus = item.status
} else {
return
}

switch item.status {
case .unknown:
debugPrint("status: unknown")
Expand All @@ -590,6 +585,29 @@ public class Player : NSObject, AVAudioPlayerDelegate {
#endif
}

// Additional code to enable respectSilentMode from here.
#if os(iOS)
do{
if #available(iOS 10.0, *) {
try AVAudioSession.sharedInstance().setCategory(category, mode: .default, options: [])
try AVAudioSession.sharedInstance().setActive(true)
} else {
try AVAudioSession.sharedInstance().setCategory(category)
try AVAudioSession.sharedInstance().setActive(true)
}
} catch let errorSetCategory {
result(FlutterError(
code: "PLAY_ERROR",
message: "Cannot play "+assetPath,
details: errorSetCategory.localizedDescription)
)
self?.log(errorSetCategory.localizedDescription)
print(errorSetCategory.localizedDescription)
return;
}
#endif
// To here.

if(autoStart == true){
self?.play()
}
Expand Down Expand Up @@ -805,6 +823,7 @@ public class Player : NSObject, AVAudioPlayerDelegate {
}

func stop(){
self.currentStatus = nil
self.player?.pause()
self.player?.rate = 0.0

Expand Down