问题
I have this code:
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);
This is my graddle file:
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'
}
I get a crash with this stacktrace:
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)
I have followed tutorials, and searched the net to see if someone has the same problem that I do, with no result.
Any guide?
Thank you.
EDIT:
After adding the code Martin told me, I am receiving this now:
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)
回答1:
AbstractMethodError
abstract method "void com.google.android.exoplayer2.upstream.DataSource.addTransferListener(com.google.android.exoplayer2.upstream.TransferListener)
means that you have to implement abstract method DataSource / RtmpDataSource .addTransferListener(TransferListener)
. Class DefaultBandwidthMeter would already implement interface
TransferListener (this could be any other class, which does that).
Try the other one constructor:
BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter();
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter);
TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
player = ExoPlayerFactory.newSimpleInstance(this, trackSelector);
来源:https://stackoverflow.com/questions/60114857/trying-to-play-an-rtmp-stream-using-exoplayer