Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<queries>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add a short comment here explaining why we need queries when we already have QUERY_ALL_PACKAGES.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It could be something as simple as "QUERY_ALL_PACKAGES does not work on X device running Android Y so we also have to specify the packages we query."

<!-- For external video players -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="video/*" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/x-mpegURL" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:mimeType="application/vnd.apple.mpegurl" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="magnet" />
</intent>

<!-- Common players -->
<package android:name="org.videolan.vlc" />
<package android:name="org.videolan.vlc.debug" />
<package android:name="is.xyz.mpv" />
<package android:name="is.xyz.mpv.ext" />
<package android:name="is.xyz.mpv.kt" />
<package android:name="is.xyz.mpv.kt.preview" />
<package android:name="com.brouken.player" />
<package android:name="com.nextplayer.pro" />
<package android:name="com.instantbits.cast.webvideo" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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


<!-- Torrent clients -->
<package android:name="org.proninyaroslav.libretorrent" />
<package android:name="com.biglybt.android.client" />
</queries>

<!-- Fixes android tv fuckery -->
<uses-feature
android:name="android.hardware.touchscreen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ object VideoDownloadManager {
)

val currentMutex = Mutex()
val current = (0 until items.size).iterator()
var currentIndex = 0

val fileMutex = Mutex()
// start to data
Expand Down Expand Up @@ -1169,8 +1169,20 @@ object VideoDownloadManager {

// mutex just in case, we never want this to fail due to multithreading
val index = currentMutex.withLock {
if (!current.hasNext()) return@launch
current.nextInt()
if (currentIndex >= items.size) return@withLock -1
val writtenIndex =
(metadata.bytesWritten - stream.startAt) / items.chuckSize
if (currentIndex > writtenIndex + (parallelConnections * 2).coerceAtLeast(5)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use metadata.bytesDownloaded and metadata.bytesWritten to ensure that you never have too much in RAM, no need to change any other logic!

This check should be placed in fileMutex.withLock to ensure that the metadata is accessed safely, but the delay should be outside the lock.

-2
} else {
currentIndex++
}
}

if (index == -1) return@launch
if (index == -2) {
delay(500)
continue
}

// in case something has gone wrong set to failed if the fail is not caused by
Expand Down Expand Up @@ -1307,7 +1319,7 @@ object VideoDownloadManager {
metadata.type = DownloadType.IsDownloading

val currentMutex = Mutex()
val current = (startAt until items.size).iterator()
var currentIndex = startAt

val fileMutex = Mutex()
val pendingData: HashMap<Int, ByteArray> = hashMapOf()
Expand Down Expand Up @@ -1341,8 +1353,18 @@ object VideoDownloadManager {

// mutex just in case, we never want this to fail due to multithreading
val index = currentMutex.withLock {
if (!current.hasNext()) return@launch
current.nextInt()
if (currentIndex >= items.size) return@withLock -1
if (currentIndex > metadata.hlsWrittenProgress + (parallelConnections * 2).coerceAtLeast(5)) {
-2
} else {
currentIndex++
}
}

if (index == -1) return@launch
if (index == -2) {
delay(500)
continue
}

// in case something has gone wrong set to failed if the fail is not caused by
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://docs.gradle.org/current/userguide/dependency_versions.html#sec:strict-version
[versions]
activityKtx = "1.13.0"
androidGradlePlugin = "9.1.1"
androidGradlePlugin = "9.0.0"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this, there is no reason to downgrade to 9.0.0.

animeDb = "1.0.2"
annotation = "1.10.0"
appcompat = "1.7.1"
Expand Down