Skip to content

VLCMedia(stream:) keeps a weak reference to the stream AND calls close() on the stream

MobileVLCKit 3.3.17

What's the reason for VLCMedia to keep only a weak reference to the stream and call hard close() when playback is finished? This combination seems to create a lot of grief for zero benefit. Here is a use case.

The UIViewController plays the stream. The user clicks [back] without stopping the playback. The controller calls player.stop() which is asynchronous and takes time. Meanwhile iOS destroys the controller and kills the hard reference to the stream, the stream is gone. Then the player calls close() on already destroyed stream without checking if it's already nil.

Anything other than this combination of weak ref & close would make more sense:

  • Want a weak reference? Then don't manage the stream for me, let me call close() in delegate or elsewhere.
  • Want to manage the stream? Keep a hard reference.
  • If you really really really want a weak reference and want to call close(), then check for nil before calling.

Your decision of weak ref & close forces me to maintain the app-level cache of streams.

Edited by Gene
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information