I am trying to transmit a camera preview in an application using the RTMP protocol. Starting from the week, I am debugging the ExoPlayer and the Librtmp client, but somehow the Librtmp client was unable to establish a connection and complain about RtmpIOException, which internally receives an error ECONNREFUSED. Tried socket programming but got the same error. IP ping is working fine. My colleague recently posted a Librtmp GitHub repo question. No response from Devs since January.
We tried with other libraries, such as IJKPlayer (which used FFmpeg internally). He was able to preview the preview, but he had a bit more time for the preview, as well as problems with turning off Wi-Fi. Unable to debug further internal due to creation using JNI.
the code:
private val bandwidthMeater = DefaultBandwidthMeter()
private val adaptiveTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeater)
private val trackSelector = DefaultTrackSelector(adaptiveTrackSelectionFactory)
private val player = ExoPlayerFactory.newSimpleInstance(context, trackSelector)
fun init() {
player.setVideoSurface(holder.surface)
}
fun startStream(streamUrl: String, startListener: () -> Unit) {
//e.g. streamUrl = rtmp://192.168.42.5:1936/live/myStream (IP is Android device IP provide by camera when connected to its wifi)
val rtmpDatasourceFactory = RtmpDatasource.RtmpDataSourceFactory()
val factory = ExtractorMediaSource.Factory(rtmpDatasourceFactory)
val extractorMediaSource =factory.createMediaSource(Uri.parse(streamUrl))
player.prepare(extractorMediaSource)
player.playWhenReady = true
}
ExoPlayer Error:
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:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
Connection error:
java.net.ConnectException: failed to connect to /192.168.42.5 (port 1936): connect failed: ECONNREFUSED (Connection refused)
source
share