在Android中使用exoplayer时出错

时间:2017-04-25 06:29:06

标签: android exoplayer

Project gradle

在我的项目gradle中使用exoplayer编译'com.google.android.exoplayer:exoplayer:r1.5.15'。 虽然包括这个版本,但是我在代码中的评论中提到的跟踪错误是exoplayer中的新内容

这是我的代码

class HpLib_HlsHpLibRendererBuilder implements HpLib_RendererBuilder {
private static final int BUFFER_SEGMENT_SIZE = 64 * 1024;
private static final int MAIN_BUFFER_SEGMENTS = 254;
private static final int AUDIO_BUFFER_SEGMENTS = 54;
private static final int TEXT_BUFFER_SEGMENTS = 2;
private final Context context;
private final String userAgent;
private final String url;
private AsyncRendererBuilder currentAsyncBuilder;

public HpLib_HlsHpLibRendererBuilder(LiveChannels player, String userAgent, String video_url) {
    this.context = player;
    this.userAgent = userAgent;
    this.url = video_url;
}
@Override
public void buildRenderers(LiveChannels player) {
    currentAsyncBuilder = new AsyncRendererBuilder(context, userAgent, url, player);
    currentAsyncBuilder.init();
}

@Override
public void cancle() {
    if(currentAsyncBuilder != null)
    {
        currentAsyncBuilder.cancel();
        currentAsyncBuilder = null;
    }
}
@Override
public void cancel() {
    if (currentAsyncBuilder != null) {
        currentAsyncBuilder.cancel();
        currentAsyncBuilder = null;
    }
}


private static final class AsyncRendererBuilder implements ManifestFetcher.ManifestCallback<HlsPlaylist> { **//Class 'AsyncRendererBuilder' must either be declared abstract or implement abstract method 'onManifest(String, T)' in 'ManifestCallback**
    private final Context context;
    private final String userAgent;
    private final String url;
    private final LiveChannels player;
    private final ManifestFetcher<HlsPlaylist> playlistFetcher;
    private boolean canceled;
    public AsyncRendererBuilder(Context context, String userAgent, String url, LiveChannels player) {
        this.context = context;
        this.userAgent = userAgent;
        this.url = url;
        this.player = player;
        HlsPlaylistParser parser = new HlsPlaylistParser();
        playlistFetcher = new ManifestFetcher<>(url, new DefaultUriDataSource(context, userAgent),
                parser);
    }
    public void init() {
        playlistFetcher.singleLoad(player.getMainHandler().getLooper(), this);//Can not resolve method 'singleLoad(android.os.Looper, com.example.pash.drm.HpLib_HlsHpLibRendererBuilder.AsyncRendererBuilder)
    }
    public void cancel() {
        canceled = true;
    }
    @Override**//Method does not override method from its superclass**
    public void onSingleManifestError(IOException e) {
        if (canceled) {
            return;
        }

        player.onRenderersError(e);
    }
    @Override //Method does not override method from its superclass
    public void onSingleManifest(HlsPlaylist manifest) {
        if (canceled) {
            return;
        }
        Handler mainHandler = player.getMainHandler();
        LoadControl loadControl = new DefaultLoadControl(new DefaultAllocator(BUFFER_SEGMENT_SIZE));
        DefaultBandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
        PtsTimestampAdjusterProvider timestampAdjusterProvider = new PtsTimestampAdjusterProvider();

        boolean haveSubtitles = false;
        boolean haveAudios = false;
        if (manifest instanceof HlsMasterPlaylist) {
            HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) manifest;
            haveSubtitles = !masterPlaylist.subtitles.isEmpty();

        }

        DataSource dataSource = new DefaultUriDataSource(context, bandwidthMeter, userAgent);
        HlsChunkSource chunkSource = new HlsChunkSource(true /* isMaster */, dataSource, manifest,
                DefaultHlsTrackSelector.newDefaultInstance(context), bandwidthMeter,
                timestampAdjusterProvider, HlsChunkSource.ADAPTIVE_MODE_SPLICE);    **//Can not resolve ADAPTIVE_MODE_SPLICE**
        HlsSampleSource sampleSource = new HlsSampleSource(chunkSource, loadControl,
                MAIN_BUFFER_SEGMENTS * BUFFER_SEGMENT_SIZE, mainHandler, player, LiveChannels.TYPE_VIDEO);
        MediaCodecVideoTrackRenderer videoRenderer = new MediaCodecVideoTrackRenderer(context, sampleSource,
                MediaCodecSelector.DEFAULT, MediaCodec.VIDEO_SCALING_MODE_SCALE_TO_FIT);**//MediaCodecVideoTrackRenderer  in MediaCodecVideoTrackRenderer cannot be applied to** 
        MediaCodecAudioTrackRenderer audioRenderer = new MediaCodecAudioTrackRenderer(sampleSource,
                MediaCodecSelector.DEFAULT);

        TrackRenderer[] renderers = new TrackRenderer[2];
        renderers[0] = videoRenderer;
        renderers[1] = audioRenderer;
        //renderers[2] = textRenderer;
        player.onRenderers(renderers, bandwidthMeter);
    }
}}

提前谢谢

1 个答案:

答案 0 :(得分:0)

很抱歉浪费你的时间我发现一些导入文件丢失了。

import com.google.android.exoplayer.util.Util;
import com.google.android.exoplayer.DefaultLoadControl;