Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProcessPidCallback to cancel a specific download #171

Closed

Conversation

HsuHsiaoHsuan
Copy link

I'm using this lib in our project and I need to find a way to cancel a specific download progress,
this is how I achieve this purpose.

https://play.google.com/store/apps/details?id=cc.ytmp3.gp

@JunkFood02 JunkFood02 changed the title Add PorcessPidCallback Add ProcessPidCallback to cancel a specific download Aug 5, 2022
@JunkFood02
Copy link
Collaborator

The idea looks good. But in my opinion, letting the library itself manage the process(es) and call Process.destroy() could be a neater option.

@xibr
Copy link
Collaborator

xibr commented Aug 6, 2022

Does it work on this method!

VideoInfo streamInfo = YoutubeDL.getInstance().getInfo("https://vimeo.com/22439234");
System.out.println(streamInfo.getTitle());
2022-08-06 19:01:39.165 7997-7997/com.yausername.youtubedl_android_example E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yausername.youtubedl_android_example, PID: 7997
    java.lang.NullPointerException: Attempt to invoke interface method 'void com.yausername.youtubedl_android.ProcessPidCallback.onProcessRun(java.lang.String)' on a null object reference
        at com.yausername.youtubedl_android.YoutubeDL.execute(YoutubeDL.java:186)
        at com.yausername.youtubedl_android.YoutubeDL.getInfo(YoutubeDL.java:128)
        at com.yausername.youtubedl_android.YoutubeDL.getInfo(YoutubeDL.java:122)
        at com.yausername.youtubedl_android_example.DownloadingExampleActivity.startDownload(DownloadingExampleActivity.java:133)
        at com.yausername.youtubedl_android_example.DownloadingExampleActivity.onClick(DownloadingExampleActivity.java:99)
        at android.view.View.performClick(View.java:7352)
        at android.widget.TextView.performClick(TextView.java:14230)
        at android.view.View.performClickInternal(View.java:7318)
        at android.view.View.access$3200(View.java:846)
        at android.view.View$PerformClick.run(View.java:27800)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:7050)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

@JunkFood02
Copy link
Collaborator

Instead of exposing the pid directly to the outside caller, my solution is that the caller manually specifies an id and then stores the key-value pair of the Process and the id in a Map. In this way, we can manage all processes more effectively and have more control through the methods provided by java.lang.Process.

@xibr
Copy link
Collaborator

xibr commented Aug 6, 2022

Instead of exposing the pid directly to the outside caller, my solution is that the caller manually specifies an id and then stores the key-value pair of the Process and the id in a Map. In this way, we can manage all processes more effectively and have more control through the methods provided by java.lang.Process.

Your solution may be better.

if (matcher.find()) {
String pidInfo[] = matcher.group().split(",\\s+");
String pidPair[] = pidInfo[0].split("=");
pidCallback.onProcessRun(pidPair[1]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check pidCallback for nullity. Otherwise java will throw NullPointerException when pidCallback is not specified.

@p3g4asus
Copy link
Collaborator

p3g4asus commented Aug 7, 2022

Please check this #173

@JunkFood02 JunkFood02 removed the request for review from yausername August 7, 2022 18:04
@HsuHsiaoHsuan
Copy link
Author

Thanks all reviews and suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants