google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.72k stars 6.03k forks source link

Kotiln does not accept nullable value exoplayer's properties #8276

Closed HyowonHwang closed 3 years ago

HyowonHwang commented 3 years ago

ExoPlayer Version: 2.12.1 Android Studio 4.1.1 Kotlin Plugin version : 1.4.10

[REQUIRED] Searched documentation and issues

[REQUIRED] Question

I've tried to write below code on my own kotlin codes. Since 2.12.1, null value is not permitted with below builder constructor.

fun defaultBandwidthMeterOf(initialBitrate : Long) = DefaultBandwidthMeter.Builder(null)  //  Putting "null" value makes compile error
        .setInitialBitrateEstimate(initialBitrate)
        .build()

I reckon that builder construct could be nullable.

스크린샷 2020-11-25 오전 11 49 31

Could you kindly let me know if there is what I missed, please?

AquilesCanta commented 3 years ago

Could you kindly let me know if there is what I missed, please?

I think you are expected to pass a non-null context. The change that made the context argument non-null is titled "Make context non-optional for DefaultBandwidthMeter", so I think the compile error is working as intended.

If the question is why there's a null check inside, then the answer is to avoid breaking code without nullability annotation checks which were already passing null, hence the "backward compatibility" comment. Please let me know if I haven't answered your question and I'll reopen the issue.

HyowonHwang commented 3 years ago

@AquilesCanta

I meant to pass null context on my kotlin codes. But I couldn't do it by compile error. I used to pass null value when DefaultBandwidthMeter.Builder(null).

AquilesCanta commented 3 years ago

Yes, unfortunately I think that's intended. Is there a reason not to pass a context as expected, aside from the potential extra plumbing required?