Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AudioDispatcher.java #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public void setVolume(float volume) throws Exception {

public void loop() throws Exception {
mediaPlayer.setLooping(true);
invokePlay(0.0, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to play from scratch when we want to loop the current music

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you reply on the last comment?
It addresses your question as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@haimomesi I have work tasks where I need to use loop without play. These are different methods, you should separate them and let the app call them when necessary

}

public void unload() throws Exception {
Expand Down
18 changes: 18 additions & 0 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ public class NativeAudio: CAPPlugin {
}

@objc func play(_ call: CAPPluginCall) {

do {
let session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSession.Category.playback, options: .mixWithOthers)
} catch{
print("Couldnt set AudioSession")
}

let audioId = call.getString(Constant.AssetIdKey) ?? ""
let time = call.getDouble("time") ?? 0
if audioId != "" {
Expand Down Expand Up @@ -137,6 +145,9 @@ public class NativeAudio: CAPPlugin {

do {
try stopAudio(audioId: audioId)
let session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSession.Category.ambient, options: .mixWithOthers)
call.success()
} catch {
call.error(Constant.ErrorAssetNotFound)
}
Expand All @@ -147,6 +158,13 @@ public class NativeAudio: CAPPlugin {
return
}

do{
let session = AVAudioSession.sharedInstance()
try session.setCategory(AVAudioSession.Category.playback, options: .mixWithOthers)
} catch{
print("Couldnt set AudioSession")
}

audioAsset.loop()
call.success()
}
Expand Down