Skip to content

Commit

Permalink
add UPlayer playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Oct 23, 2023
1 parent 9f8109b commit e2c5724
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ object Players {
if (mxIntent.resolveActivity(App.context.packageManager) != null)
return mxIntent
}
// UPlayer
if (player.contains("com.uapplication.uplayer", true)) {
val uIntent = UPlayer.getIntent(player, torrent, index)
if (uIntent.resolveActivity(App.context.packageManager) != null)
return uIntent
}
// user defined player
if (player.isNotEmpty()) {
intent.`package` = player
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.yourok.torrserve.ui.activities.play.players

import android.content.ComponentName
import android.content.Intent
import android.net.Uri
import android.os.Parcelable
import ru.yourok.torrserve.server.models.torrent.Torrent
import ru.yourok.torrserve.utils.Mime
import ru.yourok.torrserve.utils.TorrentHelper
import java.io.File

object UPlayer {
fun getIntent(pkg: String, torrent: Torrent, index: Int): Intent {
val link = TorrentHelper.getTorrentPlayLink(torrent, index)

val file = TorrentHelper.findFile(torrent, index) ?: throw Exception("file in torrent not found")

val intent = Intent(Intent.ACTION_VIEW)
intent.setPackage(pkg)
// intent.component = ComponentName(pkg, "$pkg.Comp")

val mime = Mime.getMimeType(file.path)
intent.setDataAndType(Uri.parse(link), mime)

val torrfiles = TorrentHelper.getPlayableFiles(torrent)
if (torrfiles.size > 1) {
intent.putExtra("playlistTitle", torrent.title)
val names = ArrayList<String>()
val files = ArrayList<String>()
var idx = 0
for (i in torrfiles.indices) {
names.add(File(torrfiles[i].path).name)
files.add(TorrentHelper.getFileLink(torrent, torrfiles[i]))
if (torrfiles[i].id == index) idx = i
}
intent.putExtra("titleList", names) // ArrayList<String>
intent.putExtra("videoList", files) // ArrayList<String>
intent.putExtra("playlistPosition", idx) // Int
}
return intent
}
}

0 comments on commit e2c5724

Please sign in to comment.