| | |
| | | import android.app.Service; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.os.Handler; |
| | | import android.os.IBinder; |
| | | import android.os.Looper; |
| | | import android.os.RemoteCallbackList; |
| | | import android.os.RemoteException; |
| | | |
| | |
| | | private UsbCameraRecordManager usbCameraRecordManager; |
| | | |
| | | private ManagerType currentManagerType = ManagerType.NONE; |
| | | |
| | | // 主线程 Handler,用于确保 AlivcLivePusher 初始化在主线程执行 |
| | | private final Handler mainHandler = new Handler(Looper.getMainLooper()); |
| | | |
| | | private enum ManagerType { |
| | | NONE, |
| | |
| | | return; |
| | | } |
| | | |
| | | // 确保在主线程执行,因为 AlivcLivePusher 初始化需要 Handler(必须在有 Looper 的线程) |
| | | if (Looper.myLooper() == Looper.getMainLooper()) { |
| | | startMediaInternal(media); |
| | | } else { |
| | | mainHandler.post(() -> startMediaInternal(media)); |
| | | } |
| | | } |
| | | |
| | | private void startMediaInternal(MediaArgu media) { |
| | | // 先停止当前 |
| | | stopCurrentManager(); |
| | | |
| | |
| | | } |
| | | |
| | | private void stopMedia(MediaArgu media) { |
| | | stopCurrentManager(); |
| | | // 确保在主线程执行 |
| | | if (Looper.myLooper() == Looper.getMainLooper()) { |
| | | stopCurrentManager(); |
| | | } else { |
| | | mainHandler.post(this::stopCurrentManager); |
| | | } |
| | | } |
| | | |
| | | private void stopCurrentManager() { |