MediaBrowser未连接到MediaBrowserService

时间:2018-05-13 19:34:55

标签: android android-activity foreground-service mediabrowserservice mediabrowser

我正在尝试使用MediaBrowser从活动连接到MediaBrowserService。但是,似乎永远不会调用Option Explicit Private Sub CheckBox1_Click() ' apply the checkbox value to the spreadsheet Dim rows As Range Set rows = Sheet1.Range("RowIDs") Dim cell As Range For Each cell In rows If cell.Value = ComboBox1.Value Then cell.Offset(0, 1).Value = CheckBox1.Value Exit For End If Next cell End Sub Private Sub ComboBox1_Change() ' get the value from the spreadsheet ' apply it to the checkbox Dim rows As Range Set rows = Sheet1.Range("RowIDs") Dim cell As Range For Each cell In rows If cell.Value = ComboBox1.Value Then CheckBox1.Value = cell.Offset(0, 1).Value '<<< This would be the line that causes the error Exit For End If Next cell End Sub Private Sub CommandButton1_Click() populateCombo End Sub Private Sub populateCombo() Dim rows As Range Set rows = Sheet1.Range("RowIDs") ComboBox1.Clear ComboBox1.Text = "--- Select row to activate ---" Dim cell As Range For Each cell In rows ComboBox1.AddItem cell.Value Next cell End Sub Private Sub Worksheet_Activate() UserForm1.Label1.Caption = Sheet1.Name UserForm1.Show End Sub 回调来允许我设置onConnected并开始操纵播放。

在我的播放器/浏览器活动中:

MediaController

我在调试器中添加了断点,似乎执行确实到达了服务,到了private final MediaBrowserCompat.ConnectionCallback mConnectionCallback = new MediaBrowserCompat.ConnectionCallback() { @Override public void onConnected() { try { mMediaController = new MediaControllerCompat( PlayActivity.this, mMediaBrowser.getSessionToken() ); mMediaController.registerCallback(mControllerCallback); mControllerCallback .onMetadataChanged(mMediaController.getMetadata()); mControllerCallback .onPlaybackStateChanged(mMediaController.getPlaybackState()); } catch (RemoteException e) { throw new RuntimeException(e); } mMediaController .getTransportControls() .prepareFromUri( Uri.parse( getIntent() .getStringExtra(StreamingService.STREAM_URI)), getIntent().getExtras()); mMediaController .getTransportControls().play(); buildTransportControls(); } @Override public void onConnectionSuspended() { } @Override public void onConnectionFailed() { } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true); mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, StreamingService.class), mConnectionCallback, null); } @Override public void onStart() { super.onStart(); mMediaBrowser.connect(); } 方法的末尾,但执行似乎永远不会到达onCreate或{{1我的连接回调的方法。调用onConnected后,选中onConnectionFailed将返回false。

我不确定如何进一步调试,因为问题在连接过程中的某个地方发生,并且据我所知,我的代码符合Android示例指南。是的,我在浏览器服务的connect中呼叫isConnected

如果我尝试在活动的setSessionToken中设置MediaController,在我调用onCreate之后,我会收到一个异常,说明浏览器未连接,因此无法设置会话令牌。因此,虽然执行进入我的服务的onStart,但连接没有完成。

1 个答案:

答案 0 :(得分:3)

我发现了这个错误。我在StreamingServiceMediaBrowserServiceCompat)类中重写了以下方法:

@Nullable
@Override
public IBinder onBind(Intent intent) {
    return null;
}

完全删除方法可以进行连接。