Skip to content

Commit e52de51

Browse files
committed
chore(core): add kdoc for MediaSource
[skip ci]
1 parent 130d5b7 commit e52de51

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

acidify-core/src/commonMain/kotlin/org/ntqqrev/acidify/common/ByteArrayMediaSource.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ package org.ntqqrev.acidify.common
22

33
import kotlinx.io.Buffer
44
import kotlinx.io.RawSource
5-
5+
import kotlin.js.JsExport
6+
7+
/**
8+
* 通过 [ByteArray] 构造的 [MediaSource] 实现。
9+
* 该实现会直接使用提供的 [ByteArray] 作为数据源,因此在构造时需要保证该 [ByteArray] 不会被修改,以免导致数据不一致。
10+
* 在调用 [readByteArray] 时会直接返回该 [ByteArray]。
11+
*/
12+
@JsExport
613
class ByteArrayMediaSource(private val data: ByteArray) : MediaSource() {
714
override val size: Long
815
get() = data.size.toLong()
916

17+
@JsExport.Ignore
1018
override fun openRawSource(): RawSource {
1119
return ByteArrayRawSource(data)
1220
}

acidify-core/src/commonMain/kotlin/org/ntqqrev/acidify/common/MediaSource.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,37 @@ import kotlinx.io.buffered
55
import kotlinx.io.readByteArray
66
import kotlin.js.JsExport
77

8+
/**
9+
* 表示可重复使用、可释放的媒体资源
10+
*/
811
@JsExport
912
abstract class MediaSource {
13+
/**
14+
* 资源的体积
15+
*/
1016
abstract val size: Long
1117

18+
/**
19+
* 打开一个全新的、用于访问该资源的 [RawSource] 实例
20+
*/
21+
@JsExport.Ignore
1222
abstract fun openRawSource(): RawSource
1323

14-
abstract fun dispose()
15-
24+
/**
25+
* 直接将该 [MediaSource] 的内容读取到一个 [ByteArray] 中。
26+
*/
1627
open fun readByteArray(): ByteArray {
1728
return openRawSource().buffered().use { source ->
1829
source.readByteArray()
1930
}
2031
}
2132

33+
/**
34+
* 在资源使用完毕后释放该资源。
35+
* 注意 `acidify-core` 的各个 API 都不会主动调用该方法,因此需要调用方主动释放资源。
36+
*/
37+
abstract fun dispose()
38+
2239
companion object {
2340
@JsExport.Ignore
2441
fun ByteArray.toMediaSource(): MediaSource = ByteArrayMediaSource(this)

0 commit comments

Comments
 (0)