-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: exoplayer custom datasource
- Loading branch information
Showing
34 changed files
with
436 additions
and
481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 122 additions & 4 deletions
126
android/app/src/main/java/com/kutedev/easemusicplayer/core/MusicPlayer.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
android/app/src/main/java/com/kutedev/easemusicplayer/utils/ByteQueue.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.kutedev.easemusicplayer.utils | ||
|
||
import java.util.concurrent.ConcurrentLinkedQueue | ||
import java.util.concurrent.locks.ReentrantLock | ||
import kotlin.concurrent.withLock | ||
|
||
class Item(val data: ByteArray, var remaining: Int) | ||
|
||
class ByteQueue { | ||
private val queue = ConcurrentLinkedQueue<Item>() | ||
private val lock = ReentrantLock() | ||
|
||
fun put(bytes: ByteArray) { | ||
lock.withLock { | ||
queue.add(Item(bytes, bytes.size)) | ||
} | ||
} | ||
|
||
fun isEmpty(): Boolean { | ||
lock.withLock { | ||
return queue.isEmpty() | ||
} | ||
} | ||
|
||
fun take(n: Int): ByteArray { | ||
lock.withLock { | ||
val result = ByteArray(n) | ||
var resultOffset = 0 | ||
|
||
var takeRemaining = n | ||
while (takeRemaining > 0 && queue.isNotEmpty()) { | ||
val item = queue.peek()!! | ||
|
||
val bytesToTake = minOf(takeRemaining, item.remaining) | ||
item.data.copyInto(result, resultOffset, item.data.size - item.remaining, item.data.size - item.remaining + bytesToTake) | ||
resultOffset += bytesToTake | ||
takeRemaining -= bytesToTake | ||
item.remaining -= bytesToTake | ||
|
||
if (item.remaining == 0) { | ||
queue.poll() | ||
} | ||
} | ||
return result.copyOf(resultOffset) | ||
} | ||
} | ||
|
||
fun clear() { | ||
lock.withLock { | ||
queue.clear() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.