I'm currently working on an Android app using the Media3 (ExoPlayer) library to stream video content. I've successfully implemented playback for HTTP streams, but I'm having trouble playing a UDP stream. I am using the following code to set up my ExoPlayer:
package com.itsthe1.onetv
import android.net.Uri
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.media3.common.MediaItem
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
class MainActivity : AppCompatActivity() {
private lateinit var player: ExoPlayer
private var playerView: PlayerView? = null
private val TAG = "MainActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
playerView = findViewById(R.id.player_view)
setupExoPlayer()
}
private fun setupExoPlayer() {
player = ExoPlayer.Builder(this).build().apply {
playerView?.player = this
// Replace with your UDP stream URI
val udpUri = Uri.parse("udp://@239.255.0.1:1234")
setMediaItem(MediaItem.fromUri(udpUri))
addListener(object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
Toast.makeText(this@MainActivity, "Playback error: ${error.message}", Toast.LENGTH_SHORT).show()
Log.e(TAG, "Playback error: ${error.message}")
}
})
prepare()
playWhenReady = true
}
}
override fun onStop() {
super.onStop()
player.pause()
}
override fun onDestroy() {
super.onDestroy()
player.release()
}
}
androidx.media3.exoplayer.ExoPlaybackException: Source error Caused by: androidx.media3.datasource.UdpDataSource$UdpDataSourceException: java.net.SocketTimeoutException: Poll timed out
What I've Tried: Verified the UDP stream URI and tested it with VLC Media Player. Ensured that my Android device has network access to the multicast address. Checked network settings to confirm multicast traffic is allowed. Added necessary permissions in the
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Are there specific configurations or settings needed in ExoPlayer for playing UDP streams?