1

I am working on my first Android application using Kotlin. The activity is simple, connect to an audio stream from a given URL and allow the user to pause, resume, and/or stop the stream. I've been able to connect to and play the requested audio stream using ExoPlayer, but have a problem and question that I have not found addressed in ExoPlayer documentation. I've followed this documentation as best as I can to write the following:

class StreamAudio : AppCompatActivity() {

    private lateinit var playerView: StyledPlayerView
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_stream_audio)

        // Bind PlayerView to appropriate element in layout
        playerView = findViewById(R.id.audio_player)

        // Initialize instance of ExoPlayer
        var player = ExoPlayer.Builder(applicationContext).build()

        // Set MediaItem to stream_url and play
        var stream: MediaItem = MediaItem.fromUri("http://stream_url")
        player.setMediaItem(stream)
        player.prepare()
        player.play()
    }
}
  1. When running the application the audio streams, but no StyledPlayer UI ever appears, only a solid black view. Tapping the screen does not cause any UI to appear. When substituting with a StyledPlayerControlView, the UI appears briefly before disappearing and leaving a blank white view.

  2. It seems like bad form to initialize the player within onCreate(), how can I access the player in another function? For example, to stop and release the player upon returning to the parent activity?

Thanks in advance for any help, the logs below only show an error described here that doesn't seem likely to cause UI issues.

Log Output:

W/Codec2Client: query -- param skipped: index = 1342179345.
    query -- param skipped: index = 2415921170.
E/FMQ: grantorIdx must be less than 3
    grantorIdx must be less than 3
D/CCodecBufferChannel: [c2.android.mp3.decoder#722] Created input block pool with allocatorID 16 => poolID 17 - OK (0)
I/CCodecBufferChannel: [c2.android.mp3.decoder#722] Created output block pool with allocatorID 16 => poolID 34 - OK
D/CCodecBufferChannel: [c2.android.mp3.decoder#722] Configured output block pool ids 34 => OK
E/ion: ioctl c0044901 failed with code -1: Inappropriate ioctl for device
E/FMQ: grantorIdx must be less than 3
E/FMQ: grantorIdx must be less than 3
D/AudioTrack: getTimestamp_l(24): device stall time corrected using current time 4430536774140
D/BufferPoolAccessor2.0: bufferpool2 0xe830a4d8 : 5(40960 size) total buffers - 4(32768 size) used buffers - 0/5 (recycle/alloc) - 4/410 (fetch/transfer)
D/BufferPoolAccessor2.0: evictor expired: 1, evicted: 1
John Harrington
  • 1,314
  • 12
  • 36

0 Answers0