如何在投射时从onMetadataUpdated()中检索数据?

时间:2014-09-03 05:07:08

标签: android metadata chromecast

我需要从接收器应用程序中检索一些数据(自定义数据)然后只有我可以在移动设备中更新我的发送者应用程序UI,我只是将CustomData传递给接收器应用程序,同时连接到Chromecast设备工作正常。我找到了mRemoteMediaPlayer.setOnMetadataUpdatedListener,但我怎样才能从接收器获取自定义数据?

先谢谢

我的代码部分是

if (mRemoteMediaPlayer == null || !mApiClient.isConnected()) {
            Toast.makeText(this.ctx, "No Connection", Toast.LENGTH_LONG)
                    .show();
            return;
        }
        MediaMetadata mediaMetadata = new MediaMetadata(
                MediaMetadata.MEDIA_TYPE_MUSIC_TRACK);
        mediaMetadata.putString(MediaMetadata.KEY_ALBUM_ARTIST, ""
                + singers.getText().toString());
        mediaMetadata.putString(mediaMetadata.KEY_ALBUM_TITLE, ""
                + songTitle.getText().toString());
        mediaMetadata
                .addImage(new WebImage(Uri.parse(cdImgurlList.get(0))));

MediaInfo mediaInfo = new MediaInfo.Builder(songUrl)
                .setContentType("audio/mp3")
                .setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                .setCustomData(customjsonArrayWrapper)    //here pass the customData to the receiver.
                .setMetadata(mediaMetadata).build();
        mRemoteMediaPlayer
                .load(mApiClient, mediaInfo, true)
                .setResultCallback(
                        new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                            @Override
                            public void onResult(MediaChannelResult result) {
                                if (result.getStatus().isSuccess()) {
                                    Log.d(TAG, "Media loaded Successfully"
                                            + result.getStatus());
                                    Toast.makeText(
                                            RaagaActivity.this,
                                            "Media Channel loaded Successfully"
                                                    + result.getStatus(),
                                            Toast.LENGTH_SHORT).show();
                                    // Update the UI While chrome casting
                                    UpdateUIControlsinCasting();

                                } else {
                                    Log.d(TAG,
                                            "Media loaded Not Successfully"
                                                    + result.getStatus());
                                    Toast.makeText(
                                            RaagaActivity.this,
                                            "Media Channel not loaded Successfully"
                                                    + result.getStatus(),
                                            Toast.LENGTH_SHORT).show();
                                }
                            }
                        });

    } catch (IllegalStateException e) {
        String err = (e.getMessage()==null)?"IllegalStateException":e.getMessage();
        Log.e(TAG, err);
    } catch (Exception e) {
        // TODO: handle exception
        String err = (e.getMessage()==null)?"Exception":e.getMessage();
        Log.e(TAG, err);

1 个答案:

答案 0 :(得分:0)

如果您想在元数据更新时检索自定义数据,请尝试以下操作:当调用onMetadataUpdated()的{​​{1}}时,通过调用OnMetadataUpdateListener获取MediaInfo,然后通过mediaInfo = mRemoteMediaPlayer.getMediaInfo()获取自定义数据。