尝试使用ExoPlayer播放RTMP流

问题描述 投票:0回答:1

我有此代码:

SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this);
    PlayerView playerView = findViewById(R.id.simple_player);
    playerView.setPlayer(player);

    RtmpDataSourceFactory rtmpDataSourceFactory = new RtmpDataSourceFactory();
 MediaSource videoSource = new ProgressiveMediaSource.Factory(rtmpDataSourceFactory)
            .createMediaSource(Uri.parse("https://player.cdnmedia.tv/embed/a77aa67c"));
player.prepare(videoSource);
player.setPlayWhenReady(true);

这是我的毕业文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "my.company.streaming"
    minSdkVersion 26
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.exoplayer:exoplayer:2.10.3'
implementation 'com.google.android.exoplayer:extension-rtmp:2.7.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

我在此堆栈跟踪中崩溃:

java.lang.AbstractMethodError: abstract method "void com.google.android.exoplayer2.upstream.DataSource.addTransferListener(com.google.android.exoplayer2.upstream.TransferListener)"
    at com.google.android.exoplayer2.source.ProgressiveMediaSource.createPeriod(ProgressiveMediaSource.java:246)
    at com.google.android.exoplayer2.source.ExtractorMediaSource.createPeriod(ExtractorMediaSource.java:354)
    at com.google.android.exoplayer2.MediaPeriodHolder.createMediaPeriod(MediaPeriodHolder.java:417)
    at com.google.android.exoplayer2.MediaPeriodHolder.<init>(MediaPeriodHolder.java:92)
    at com.google.android.exoplayer2.MediaPeriodQueue.enqueueNextMediaPeriod(MediaPeriodQueue.java:149)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.maybeUpdateLoadingPeriod(ExoPlayerImplInternal.java:1623)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.updatePeriods(ExoPlayerImplInternal.java:1492)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:552)
    at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:326)
    at android.os.Handler.dispatchMessage(Handler.java:101)
    at android.os.Looper.loop(Looper.java:164)
    at android.os.HandlerThread.run(HandlerThread.java:65)

我遵循了教程,并在网上搜索是否有人遇到与我相同的问题,但没有结果。

任何指南?

谢谢。

编辑:

添加了马丁告诉我的代码后,我现在就收到了:

E/ExoPlayerImplInternal: Source error.
net.butterflytv.rtmp_client.RtmpClient$RtmpIOException
    at net.butterflytv.rtmp_client.RtmpClient.open(RtmpClient.java:56)
    at com.google.android.exoplayer2.ext.rtmp.RtmpDataSource.open(RtmpDataSource.java:57)
    at com.google.android.exoplayer2.source.ExtractorMediaPeriod$ExtractingLoadable.load(ExtractorMediaPeriod.java:841)
    at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:308)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)
android video-streaming rtmp exoplayer
1个回答
0
投票

[AbstractMethodError abstract method "void com.google.android.exoplayer2.upstream.DataSource.addTransferListener(com.google.android.exoplayer2.upstream.TransferListener)意味着您必须实现抽象方法DataSource /DataSourceRtmpDataSource。类RtmpDataSource已经实现了.addTransferListener(TransferListener) DefaultBandwidthMeter(这可以是任何其他这样做的类)。

尝试其他一个构造函数:

DefaultBandwidthMeter
© www.soinside.com 2019 - 2024. All rights reserved.