4

我想通过 MediaRouter 类将音频文件从我的 android 设备流式传输到另一个设备。据我了解,我需要

mediarouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_AUDIO, mCallback);

功能以侦听连接的设备是否正在播放音频。但是我不确定。我的问题是如何获取音频流?

4

1 回答 1

1

If you play your audio using AudioTrack you need to make sure that the streamType matches the route's streamType. To get the route's streamType, simply do:

private final MediaRouter.Callback mMediaRouterCallback =
    new MediaRouter.Callback() {

        @Override
        public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo route) {
                Log.i(TAG, "streamType = " + route.getPlaybackStream());
        }
};

Usually it will be AudioManager.STREAM_MUSIC. So when you initialize your AudioTrack make sure to:

_audioTrack = new AudioTrack(
                AudioManager.STREAM_MUSIC,
                sampleRate,
                channelConfig,
                audioFormat,
                bufferSize, 
                mode);
于 2014-11-06T22:34:40.840 回答