-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
...ager/SoraAudioManager/src/main/java/jp/shiguredo/sora/audiomanager/MainThreadWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package jp.shiguredo.sora.audiomanager; | ||
|
||
import android.content.Context; | ||
|
||
class MainThreadWrapper extends SoraAudioManager { | ||
private SoraAudioManager soraAudioManager; | ||
|
||
private static class OnChangeRouteObserver implements SoraAudioManager.OnChangeRouteObserver { | ||
SoraAudioManager.OnChangeRouteObserver observer; | ||
|
||
public OnChangeRouteObserver(SoraAudioManager.OnChangeRouteObserver observer) { | ||
this.observer = observer; | ||
} | ||
|
||
public void OnChangeRoute() { | ||
//メインスレッドでない場合はメインスレッドで再実行 | ||
if (!SoraThreadUtils.runOnMainThread(this::OnChangeRoute)) { | ||
return; | ||
} | ||
|
||
if (this.observer == null) { | ||
return; | ||
} | ||
this.observer.OnChangeRoute(); | ||
} | ||
} | ||
|
||
MainThreadWrapper(Context context) { | ||
//メインスレッドでない場合はメインスレッドで再実行 | ||
if (!SoraThreadUtils.runOnMainThread(() -> { | ||
this.soraAudioManager = SoraAudioManagerFactory.create(context); | ||
})) { | ||
return; | ||
} | ||
this.soraAudioManager = SoraAudioManagerFactory.create(context); | ||
} | ||
|
||
@Override | ||
public void start(SoraAudioManager.OnChangeRouteObserver observer) { | ||
//メインスレッドでない場合はメインスレッドで再実行 | ||
if (!SoraThreadUtils.runOnMainThread(() -> start(observer))) { | ||
return; | ||
} | ||
soraAudioManager.start(new OnChangeRouteObserver(observer)); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
//メインスレッドでない場合はメインスレッドで再実行 | ||
if (!SoraThreadUtils.runOnMainThread(this::stop)) { | ||
return; | ||
} | ||
soraAudioManager.stop(); | ||
} | ||
|
||
@Override | ||
public void setHandsfree(boolean on) { | ||
//メインスレッドでない場合はメインスレッドで再実行 | ||
if (!SoraThreadUtils.runOnMainThread(() -> setHandsfree(on))) { | ||
return; | ||
} | ||
soraAudioManager.setHandsfree(on); | ||
} | ||
|
||
@Override | ||
public boolean isHandsfree() { | ||
return soraAudioManager.isHandsfree(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters