se-bastiaan / TorrentStream-Android

A torrent streamer library for Android based on libtorrent4j
Other
343 stars 108 forks source link

Help with using the library #55

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hi, thanks for creating this library. I simply want to download a torrent that contains some files, I don't need to play them. I tried sample and it worked great but below code doesn't seem to be working, am I doing something wrong? (I am using 2.5.0)

`class FragmentDownloads : Fragment(), TorrentListener { override fun onStreamReady(torrent: Torrent?) { println("Torrent : onStreamReady") }

override fun onStreamPrepared(torrent: Torrent?) {
    println("Torrent : onStreamPrepared")
    // If you set TorrentOptions#autoDownload(false) then this is probably the place to call
    // torrent.startDownload();
}

override fun onStreamStopped() {
    println("Torrent : onStreamStopped")
}

override fun onStreamStarted(torrent: Torrent?) {
    println("Torrent : onStreamStarted")
}

override fun onStreamProgress(torrent: Torrent?, status: StreamStatus?) {
    println("Torrent : onStreamProgress")
    println(status?.bufferProgress)
}

override fun onStreamError(torrent: Torrent?, p1: Exception?) {
    println("Torrent : onStreamError")
}

var torrentStream: TorrentStream? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    val v = inflater.inflate(R.layout.fragment_downloads, container, false)
    return v
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    doAsync {
        val torrentOptions = TorrentOptions.Builder()
            .saveLocation(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS))
            .removeFilesAfterStop(true)
            .build()
        torrentStream = TorrentStream.init(torrentOptions)
        torrentStream!!.addListener(this@FragmentDownloads)
        var magnet = "magnet:?whateverurl"
        torrentStream!!.startStream(magnet)
        println("STARTED")
    }
}

}`

ghost commented 5 years ago

Logs `2019-07-26 23:01:19.578 16475-18037/ I/System.out: STARTED

2019-07-26 23:01:19.797 16475-18035/ W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...

2019-07-26 23:01:19.804 16475-18035/ D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 0 0

2019-07-26 23:01:19.805 16475-18035/ D/EGL_emulation: eglCreateContext: 0x7a37aa88a860: maj 2 min 0 rcv 2

2019-07-26 23:01:19.807 16475-18035/ D/EGL_emulation: eglMakeCurrent: 0x7a37aa88a860: ver 2 0 (tinfo 0x7a37aa818c80)

2019-07-26 23:01:19.827 16475-18035/ W/Gralloc3: mapper 3.x is not supported

2019-07-26 23:01:19.880 16475-18035/ D/EGL_emulation: eglMakeCurrent: 0x7a37aa88a860: ver 2 0 (tinfo 0x7a37aa818c80)

2019-07-26 23:01:19.887 16475-18035/ D/eglCodecCommon: setVertexArrayObject: set vao to 0 (0) 1 0`

se-bastiaan commented 5 years ago

Are those all the logs you have? The process of the first message and the others is different so it seems.

ghost commented 5 years ago

Yeah, those were all the logs and I figured that all other lines except first were due to frame skipping.

ghost commented 5 years ago

@se-bastiaan It seems that torrentStream.isStreaming is returning false for above code, is there any other example which shows the use of the library, I am afraid I may not have done things carefully enough even when I am able to use the all the classes in my code. I only need to download a single file from the torrent and it would be really cool if I could do it using the TorrentStream because this stuff is otherwise too complex for me.

Project's build.gradle file: ` // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { ext.kotlin_version = '1.3.41' repositories { google() jcenter()

}
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.2'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects { repositories { google() jcenter() maven { url "https://jitpack.io" } } }

task clean(type: Delete) { delete rootProject.buildDir } `

App's build.gradle file: ` apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android { compileSdkVersion 29 buildToolsVersion "29.0.0" defaultConfig { applicationId "app.name.solution" minSdkVersion 19 targetSdkVersion 29 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } }

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'org.jetbrains.anko:anko-common:0.9' implementation 'androidx.recyclerview:recyclerview:1.0.0' implementation "com.github.TorrentStream:TorrentStream-Android:2.5.0" }

`

se-bastiaan commented 5 years ago

Are you trying to download a video file? If there is none in the meta of the torrent it won't do anything.

ghost commented 5 years ago

Yes I am downloading a video file. It's just that I can't seem to get the Torrent Stream example to work in another app, after adding its jitpack repo to the build.

ghost commented 5 years ago

After some more unsuccessful attempts, I tried a similar project at https://github.com/masterwok/simple-torrent-android which seems to be working for my use case. Anyway, thanks for all the fish. I am closing this issue.