Skip to content

Commit e92530b

Browse files
Nevermore1994rolf.tan
authored andcommitted
update doc
1 parent 7329b44 commit e92530b

File tree

4 files changed

+356
-135
lines changed

4 files changed

+356
-135
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66

77
- [中文文档](README_zh.md)
88

9-
Slark is a high-performance cross-platform video player that supports iOS and Android platforms. Built with modern C++23 for core functionality, it delivers native performance and rich multimedia playback features.
10-
11-
## ✨ Key Features
12-
13-
- 🎵 **Multi-format Support**: Supports MP4, HLS, WAV and other audio/video formats
14-
- 🌐 **Network Streaming**: Supports both local files and network media streaming
15-
- 📱 **Cross-platform**: Single core codebase supports both iOS and Android
16-
- 🛠️ **Modern Architecture**: Built with C++23 standard, supporting modern C++ features
9+
Slark is a cross-platform video player that supports iOS and Android platforms. Built from the ground up with modern C++23, it provides a streamlined media playback solution with minimal dependencies (only OpenSSL for HTTPS support).
1710

1811
## 🔧 Supported Platforms
1912

README_zh.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66

77
- [English Documentation](README.md)
88

9-
Slark 是一个高性能跨平台视频播放器,支持 iOS 和 Android 平台。核心功能采用现代 C++23 构建,提供原生性能和丰富的多媒体播放功能。
10-
11-
## ✨ 主要特性
12-
13-
- 🎵 **多格式支持**:支持 MP4、HLS、WAV 等音视频格式
14-
- 🌐 **网络流媒体**:支持本地文件和网络媒体流播放
15-
- 📱 **跨平台**:单一核心代码库同时支持 iOS 和 Android
16-
- 🛠️ **现代架构**:基于 C++23 标准构建,支持现代 C++ 特性
9+
Slark 是一款跨平台视频播放器,支持 iOS 和 Android 平台。采用现代 C++23 从零构建,提供精简的媒体播放解决方案,具有极少的外部依赖(仅在 HTTPS 支持时需要 OpenSSL)。
1710

1811
## 🔧 支持平台
1912

docs/android-api.md

Lines changed: 94 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
## Android API 文档
33

4-
```markdown:docs/android-api.md
54
# Slark Android API Documentation
65

76
Slark Android SDK provides complete media playback functionality, supporting both local file and network streaming media playback.
@@ -20,7 +19,8 @@ Slark Android SDK provides complete media playback functionality, supporting bot
2019
- [PlayerErrorCode](#playererrorcode)
2120
- [Render Target](#render-target)
2221
- [SlarkRenderTarget](#slarkrendertarget)
23-
- [Time Range](#time-range)
22+
- [Time Classes](#time-classes)
23+
- [KtTime](#kttime)
2424
- [KtTimeRange](#kttimerange)
2525
- [Usage Examples](#usage-examples)
2626

@@ -276,6 +276,20 @@ enum class PlayerErrorCode {
276276
DemuxError, // Demux error
277277
DecodeError, // Decode error
278278
RenderError; // Render error
279+
280+
companion object {
281+
fun fromString(value: String): PlayerErrorCode? {
282+
return when (value.toInt()) {
283+
0 -> OpenFileError
284+
1 -> NetWorkError
285+
2 -> NotSupport
286+
3 -> DemuxError
287+
4 -> DecodeError
288+
5 -> RenderError
289+
else -> null
290+
}
291+
}
292+
}
279293
}
280294
```
281295

@@ -307,20 +321,70 @@ sealed class SlarkRenderTarget {
307321
- Maximum flexibility
308322
- Requires manual size management
309323

310-
## Time Range
324+
## Time Classes
325+
326+
### KtTime
327+
328+
Time representation class with precision control.
329+
330+
```kotlin
331+
data class KtTime(val value: Long, val timescale: Int = 1000) : Comparable<KtTime> {
332+
fun toSeconds(): Double
333+
334+
operator fun plus(other: KtTime): KtTime
335+
operator fun minus(other: KtTime): KtTime
336+
337+
fun isValid(): Boolean
338+
339+
companion object {
340+
fun fromSeconds(seconds: Double, timescale: Int = 600): KtTime
341+
val zero: KtTime
342+
}
343+
}
344+
```
345+
346+
#### Properties and Methods
347+
348+
- **value**: Time value in the specified timescale units
349+
- **timescale**: Number of units per second (default: 1000 for milliseconds)
350+
- **toSeconds()**: Convert to seconds as Double
351+
- **fromSeconds()**: Create KtTime from seconds
352+
- **Arithmetic operators**: Support addition and subtraction
353+
- **Comparison**: Implements Comparable interface
311354

312355
### KtTimeRange
313356

314357
Time range class for specifying playback time segments.
315358

316359
```kotlin
317360
data class KtTimeRange(val start: KtTime, val duration: KtTime) {
361+
val end: KtTime
362+
363+
fun get(): Pair<Double, Double>
364+
fun contains(time: KtTime): Boolean
365+
fun isOverlap(other: KtTimeRange): Boolean
366+
fun overlap(other: KtTimeRange): KtTimeRange?
367+
fun union(other: KtTimeRange): KtTimeRange?
368+
fun isValid(): Boolean
369+
318370
companion object {
319-
val zero = KtTimeRange(KtTime.zero, KtTime.zero)
371+
val zero: KtTimeRange
320372
}
321373
}
322374
```
323375

376+
#### Properties and Methods
377+
378+
- **start**: Start time of the range
379+
- **duration**: Duration of the range
380+
- **end**: Computed end time (start + duration)
381+
- **get()**: Returns start and end times as seconds pair
382+
- **contains()**: Check if a time is within the range
383+
- **isOverlap()**: Check if two ranges overlap
384+
- **overlap()**: Get overlapping portion of two ranges
385+
- **union()**: Combine two ranges into one
386+
- **isValid()**: Check if range is valid
387+
324388
## Usage Examples
325389

326390
### Basic Playback Flow
@@ -334,23 +398,20 @@ class PlayerActivity : AppCompatActivity(), SlarkPlayerObserver {
334398
super.onCreate(savedInstanceState)
335399
setContentView(R.layout.activity_player)
336400

337-
// 1. Initialize SDK
338-
SlarkSdk.init(application)
339-
340-
// 2. Create player configuration
401+
// 1. Create player configuration
341402
val config = SlarkPlayerConfig("https://example.com/video.mp4")
342403

343-
// 3. Create player
404+
// 2. Create player
344405
player = SlarkPlayerFactory.createPlayer(config)
345406

346-
// 4. Set observer
407+
// 3. Set observer
347408
player?.setObserver(this)
348409

349-
// 5. Set render target
410+
// 4. Set render target
350411
textureView = findViewById(R.id.texture_view)
351412
player?.setRenderTarget(SlarkRenderTarget.FromTextureView(textureView))
352413

353-
// 6. Prepare for playback
414+
// 5. Prepare for playback
354415
player?.prepare()
355416
}
356417

@@ -377,15 +438,15 @@ class PlayerActivity : AppCompatActivity(), SlarkPlayerObserver {
377438
}
378439

379440
// SlarkPlayerObserver implementation
380-
override fun onTimeUpdate(playerId: String, time: Double) {
441+
override fun notifyTime(playerId: String, time: Double) {
381442
// Update playback progress UI
382443
runOnUiThread {
383444
Log.d("Player", "Playback time: $time")
384445
// Update progress bar
385446
}
386447
}
387448

388-
override fun onStateChanged(playerId: String, state: SlarkPlayerState) {
449+
override fun notifyState(playerId: String, state: SlarkPlayerState) {
389450
runOnUiThread {
390451
when (state) {
391452
SlarkPlayerState.Playing -> {
@@ -406,7 +467,7 @@ class PlayerActivity : AppCompatActivity(), SlarkPlayerObserver {
406467
}
407468
}
408469

409-
override fun onEvent(playerId: String, event: SlarkPlayerEvent, value: String) {
470+
override fun notifyEvent(playerId: String, event: SlarkPlayerEvent, value: String) {
410471
runOnUiThread {
411472
when (event) {
412473
SlarkPlayerEvent.FirstFrameRendered -> {
@@ -451,6 +512,22 @@ class AudioPlayerActivity : AppCompatActivity(), SlarkPlayerObserver {
451512
}
452513
```
453514

515+
### Time Range Playback Example
516+
517+
```kotlin
518+
// Play specific time range
519+
val startTime = KtTime.fromSeconds(30.0) // Start at 30 seconds
520+
val duration = KtTime.fromSeconds(60.0) // Play for 60 seconds
521+
val timeRange = KtTimeRange(startTime, duration)
522+
523+
val config = SlarkPlayerConfig(
524+
dataSource = "https://example.com/video.mp4",
525+
timeRange = timeRange
526+
)
527+
528+
val player = SlarkPlayerFactory.createPlayer(config)
529+
```
530+
454531
### Different Render Target Examples
455532

456533
```kotlin
@@ -494,7 +571,7 @@ class PlayerActivity : AppCompatActivity() {
494571
### Error Handling
495572

496573
```kotlin
497-
override fun onEvent(playerId: String, event: SlarkPlayerEvent, value: String) {
574+
override fun notifyEvent(playerId: String, event: SlarkPlayerEvent, value: String) {
498575
when (event) {
499576
SlarkPlayerEvent.OnError -> {
500577
val errorCode = PlayerErrorCode.fromString(value)
@@ -528,6 +605,7 @@ override fun onEvent(playerId: String, event: SlarkPlayerEvent, value: String) {
528605
3. **Resource Management**: Call `release()` method in time to release player resources
529606
4. **Network Permissions**: Network playback requires adding network permissions in AndroidManifest.xml
530607
5. **Lifecycle**: Properly handle application lifecycle to avoid memory leaks
608+
6. **Time Precision**: Use KtTime for precise time calculations and KtTimeRange for time segments
531609

532610
## Permission Configuration
533611

0 commit comments

Comments
 (0)