Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Not working when torrent has multiple files #16

Open
jayaram9877 opened this issue Jul 1, 2022 · 6 comments
Open

Not working when torrent has multiple files #16

jayaram9877 opened this issue Jul 1, 2022 · 6 comments

Comments

@jayaram9877
Copy link

jayaram9877 commented Jul 1, 2022

Works pretty well when the torrent has a single video file but never calls onServerReady

void initializeServer(int port, int fileIndex) {
    selectedFileIndex = fileIndex;
    System.out.println("Selecteed index is"+ fileIndex);
    TorrentOptions torrentOptions = new TorrentOptions.Builder()
            .saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
            .removeFilesAfterStop(true)
           .autoDownload(false)
            .build();

    String ipAddress = "127.0.0.1";
    try {
        ipAddress = getIpAddress();

    } catch (Exception e) {
        e.printStackTrace();
    }

    torrentStreamServer = TorrentStreamServer.getInstance();
    torrentStreamServer.setTorrentOptions(torrentOptions);
    torrentStreamServer.setServerHost(ipAddress);
    torrentStreamServer.setServerPort(8080);
    torrentStreamServer.startTorrentStream();
    torrentStreamServer.addListener(this);

    try {
        torrentStreamServer.startStream(torrentInfo, torrentPath);
    } catch (TorrentStreamNotInitializedException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}
@Override
public void onStreamError(Torrent torrent, Exception e) {
    System.out.println("Stream Error"+ e.toString());

}

@Override
public void onStreamReady(Torrent torrent) {
    System.out.println("Stream ready" );

}

@Override
public void onStreamProgress(Torrent torrent, StreamStatus status) {

    System.out.println("Progress is"+ status.progress +" and current interested byte is"+ torrent.getInterestedPieceIndex());
}

@Override
public void onStreamStopped() {
    System.out.println("Stream stopped");

}

@Override
public void onServerReady(String url) {
    System.out.println("Serving on "+ url);

}
@se-bastiaan
Copy link
Owner

se-bastiaan commented Jul 1, 2022

You do not seem to have a onStreamPrepared listener where you start the download on the torrent handle, but you have set autoDownload to false. Are you sure this code downloads anything at all?

The library should select the largest file in the torrent. You do no seem to use your selected file index as well.

@jayaram9877
Copy link
Author

Sorry forgot to attach onStreamPrepared above below is what I am doing there and yes its downloading the torrent till 100 and onServerReady is never called.

    @Override
    public void onStreamPrepared(Torrent torrent) {
        System.out.println("Stream Preapred");
        torrent.setSelectedFileIndex(selectedFileIndex);
        torrent.startDownload();
    }

@jayaram9877
Copy link
Author

Any workaround on this?

@se-bastiaan
Copy link
Owner

Are you sure the selected file index is correct? There are no logs that you have?

@se-bastiaan
Copy link
Owner

You may want to try the latest version, since it has a fully updated libtorrent version due to upstream updates.

@jayaram9877
Copy link
Author

There is nothing in the logs. It is printing the progress till 100 and nothing happens after that.

I'll try the new version today and update it here.

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

No branches or pull requests

2 participants