yausername / youtubedl-android

youtube-dl for android
GNU General Public License v3.0
947 stars 172 forks source link

Error when building app with incompatible type on "DownloadProgressCallback" #232

Closed 8mpty closed 1 year ago

8mpty commented 1 year ago

error is

error: incompatible types: DownloadProgressCallback cannot be converted to Function3<? super Float,? super Long,? super String,Unit>

from Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().execute(request, processId, callback))

and my "callback" is something like this

private final DownloadProgressCallback callback = new DownloadProgressCallback() {
        @Override
        public void onProgressUpdate(float progress, long etaInSeconds, String line) {

            newprogress = progress;
            final int max = 100;
            createNotificationChannel();
            downloadNoti(max);

            Runnable download = () -> {
                for(newprogress = 0; newprogress <= max; newprogress++) {
                    builder.setProgress(max,(int)newprogress,false);
                    notificationManager.notify(2,builder.build());
                }
            };
            Thread thread = new Thread(download);
            thread.start();
        }

was not having issues all this time and everything would build and run well only,until recently would this error pop up. I did not touch my could for about 1 week and it was working fine before.

I followed android studio suggestion to help fix my code and this is the suggestion: Disposable disposable = Observable.fromCallable(() -> YoutubeDL.getInstance().execute(request, processId, (Function3<? super Float, ? super Long, ? super String, Unit>) callback))

My app will run now but I don't know what caused this issue and I'm sure there is a better way of fixing this.

*Edit: Nevermind, app won't download anymore after implementing this fix XD with java.lang.ClassCastException: cannot be cast to kotlin.jvm.functions.Function3

*Edit2: could be caused by commit https://github.com/yausername/youtubedl-android/commit/97bee6c0e824b31a2a438800a48012b24de5f24e as everything was working before that. I'm not sure how will that mess with my project though..

JunkFood02 commented 1 year ago

The library was rewritten in Kotlin, for calling this library in Java, check this

8mpty commented 1 year ago

The library was rewritten in Kotlin, for calling this library in Java, check this

Ahhh, i see. Thanks for the fast reply and everything is working fine now. Thanks a lot!