-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAssetManager.swift
More file actions
55 lines (44 loc) · 1.21 KB
/
AssetManager.swift
File metadata and controls
55 lines (44 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// AssetManager.swift
// SwiftAndroid
//
// Created by Alsey Coleman Miller on 2/27/26.
//
#if os(Android)
import Android
import AndroidNDK
#endif
/// Wrapper around Android `AAssetManager`.
public struct AssetManager: @unchecked Sendable {
internal let pointer: OpaquePointer
/// Creates a manager from an existing native pointer.
public init(_ pointer: OpaquePointer) {
self.pointer = pointer
}
}
// MARK: - Methods
public extension AssetManager {
/// Opens an asset by path.
///
/// - Parameters:
/// - path: Relative path under the APK `assets/` directory.
/// - mode: Access hint for Android's asset backend.
func open(_ path: String, mode: AssetMode = .streaming) throws(AndroidFileManagerError) -> Asset {
guard let pointer = path.withCString({
AAssetManager_open(pointer, $0, mode.rawValue)
}) else {
throw .openAsset(path)
}
return Asset(pointer)
}
}
// MARK: - Supporting Types
public extension AssetManager {
/// `AAssetManager_open` mode flags.
enum AssetMode: Int32, Sendable {
case unknown = 0
case random = 1
case streaming = 2
case buffer = 3
}
}