expo-mpv 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "expo-mpv",
3
+ "version": "0.1.0",
4
+ "description": "My new module",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "scripts": {
8
+ "build": "expo-module build",
9
+ "clean": "expo-module clean",
10
+ "lint": "expo-module lint",
11
+ "test": "expo-module test",
12
+ "prepare": "expo-module prepare",
13
+ "prepublishOnly": "expo-module prepublishOnly",
14
+ "expo-module": "expo-module",
15
+ "open:ios": "xed example/ios",
16
+ "open:android": "open -a \"Android Studio\" example/android"
17
+ },
18
+ "keywords": [
19
+ "react-native",
20
+ "expo",
21
+ "expo-mpv",
22
+ "ExpoMpv"
23
+ ],
24
+ "repository": "https://github.com/lonzzi/expo-mpv",
25
+ "bugs": {
26
+ "url": "https://github.com/lonzzi/expo-mpv/issues"
27
+ },
28
+ "author": "lonzzi <lonzzi@qq.com> (https://github.com/lonzzi)",
29
+ "license": "MIT",
30
+ "homepage": "https://github.com/lonzzi/expo-mpv#readme",
31
+ "dependencies": {},
32
+ "devDependencies": {
33
+ "@types/react": "~19.1.1",
34
+ "expo-module-scripts": "^55.0.2",
35
+ "expo": "^55.0.11",
36
+ "react-native": "0.83.4"
37
+ },
38
+ "peerDependencies": {
39
+ "expo": "*",
40
+ "react": "*",
41
+ "react-native": "*"
42
+ }
43
+ }
@@ -0,0 +1,145 @@
1
+ import type { StyleProp, ViewStyle } from 'react-native';
2
+
3
+ // MARK: - Event Payloads
4
+
5
+ export type PlaybackStateChangeEvent = {
6
+ state: 'playing' | 'paused' | 'stopped';
7
+ isPlaying: boolean;
8
+ };
9
+
10
+ export type ProgressEvent = {
11
+ position: number;
12
+ duration: number;
13
+ bufferedDuration: number;
14
+ };
15
+
16
+ export type LoadEvent = {
17
+ duration: number;
18
+ width: number;
19
+ height: number;
20
+ };
21
+
22
+ export type ErrorEvent = {
23
+ error: string;
24
+ };
25
+
26
+ export type EndEvent = {
27
+ reason: 'ended' | 'error' | 'stopped' | 'unknown';
28
+ };
29
+
30
+ export type BufferEvent = {
31
+ isBuffering: boolean;
32
+ };
33
+
34
+ export type SeekEvent = {};
35
+
36
+ export type VolumeChangeEvent = {
37
+ volume: number;
38
+ muted: boolean;
39
+ };
40
+
41
+ export type PlaybackInfo = {
42
+ position: number;
43
+ duration: number;
44
+ isPlaying: boolean;
45
+ speed: number;
46
+ volume: number;
47
+ muted: boolean;
48
+ };
49
+
50
+ // MARK: - Module Events (non-view)
51
+
52
+ export type ExpoMpvModuleEvents = {};
53
+
54
+ // MARK: - View Props
55
+
56
+ export type ExpoMpvViewProps = {
57
+ /**
58
+ * Media source URL to play. Can be a remote URL or a local file path.
59
+ */
60
+ source?: string;
61
+
62
+ /**
63
+ * Whether playback is paused.
64
+ */
65
+ paused?: boolean;
66
+
67
+ /**
68
+ * Playback speed multiplier. Default is 1.0.
69
+ */
70
+ speed?: number;
71
+
72
+ /**
73
+ * Volume level (0-100). Default is 100.
74
+ */
75
+ volume?: number;
76
+
77
+ /**
78
+ * Whether audio is muted.
79
+ */
80
+ muted?: boolean;
81
+
82
+ /**
83
+ * Whether to loop the current file.
84
+ */
85
+ loop?: boolean;
86
+
87
+ /**
88
+ * Called when playback state changes (play/pause).
89
+ */
90
+ onPlaybackStateChange?: (event: { nativeEvent: PlaybackStateChangeEvent }) => void;
91
+
92
+ /**
93
+ * Called periodically with current playback progress.
94
+ */
95
+ onProgress?: (event: { nativeEvent: ProgressEvent }) => void;
96
+
97
+ /**
98
+ * Called when a media file has been loaded and is ready to play.
99
+ */
100
+ onLoad?: (event: { nativeEvent: LoadEvent }) => void;
101
+
102
+ /**
103
+ * Called when an error occurs.
104
+ */
105
+ onError?: (event: { nativeEvent: ErrorEvent }) => void;
106
+
107
+ /**
108
+ * Called when playback reaches the end.
109
+ */
110
+ onEnd?: (event: { nativeEvent: EndEvent }) => void;
111
+
112
+ /**
113
+ * Called when buffering state changes.
114
+ */
115
+ onBuffer?: (event: { nativeEvent: BufferEvent }) => void;
116
+
117
+ /**
118
+ * Called when a seek operation completes.
119
+ */
120
+ onSeek?: (event: { nativeEvent: SeekEvent }) => void;
121
+
122
+ /**
123
+ * Called when volume or mute state changes.
124
+ */
125
+ onVolumeChange?: (event: { nativeEvent: VolumeChangeEvent }) => void;
126
+
127
+ style?: StyleProp<ViewStyle>;
128
+ };
129
+
130
+ // MARK: - View Ref Methods
131
+
132
+ export type ExpoMpvViewRef = {
133
+ play: () => Promise<void>;
134
+ pause: () => Promise<void>;
135
+ togglePlay: () => Promise<void>;
136
+ stop: () => Promise<void>;
137
+ seekTo: (position: number) => Promise<void>;
138
+ seekBy: (offset: number) => Promise<void>;
139
+ setSpeed: (speed: number) => Promise<void>;
140
+ setVolume: (volume: number) => Promise<void>;
141
+ setMuted: (muted: boolean) => Promise<void>;
142
+ setSubtitleTrack: (trackId: number) => Promise<void>;
143
+ setAudioTrack: (trackId: number) => Promise<void>;
144
+ getPlaybackInfo: () => Promise<PlaybackInfo>;
145
+ };
@@ -0,0 +1,8 @@
1
+ import { NativeModule, requireNativeModule } from 'expo';
2
+
3
+ import { ExpoMpvModuleEvents } from './ExpoMpv.types';
4
+
5
+ declare class ExpoMpvModule extends NativeModule<ExpoMpvModuleEvents> {}
6
+
7
+ // This call loads the native module object from the JSI.
8
+ export default requireNativeModule<ExpoMpvModule>('ExpoMpv');
@@ -0,0 +1,33 @@
1
+ import { requireNativeView } from 'expo';
2
+ import * as React from 'react';
3
+ import { forwardRef, useImperativeHandle, useRef } from 'react';
4
+
5
+ import { ExpoMpvViewProps, ExpoMpvViewRef } from './ExpoMpv.types';
6
+
7
+ const NativeView: React.ComponentType<ExpoMpvViewProps & { ref?: React.Ref<any> }> =
8
+ requireNativeView('ExpoMpv');
9
+
10
+ const ExpoMpvView = forwardRef<ExpoMpvViewRef, ExpoMpvViewProps>((props, ref) => {
11
+ const nativeRef = useRef<any>(null);
12
+
13
+ useImperativeHandle(ref, () => ({
14
+ play: () => nativeRef.current?.play(),
15
+ pause: () => nativeRef.current?.pause(),
16
+ togglePlay: () => nativeRef.current?.togglePlay(),
17
+ stop: () => nativeRef.current?.stop(),
18
+ seekTo: (position: number) => nativeRef.current?.seekTo(position),
19
+ seekBy: (offset: number) => nativeRef.current?.seekBy(offset),
20
+ setSpeed: (speed: number) => nativeRef.current?.setSpeed(speed),
21
+ setVolume: (volume: number) => nativeRef.current?.setVolume(volume),
22
+ setMuted: (muted: boolean) => nativeRef.current?.setMuted(muted),
23
+ setSubtitleTrack: (trackId: number) => nativeRef.current?.setSubtitleTrack(trackId),
24
+ setAudioTrack: (trackId: number) => nativeRef.current?.setAudioTrack(trackId),
25
+ getPlaybackInfo: () => nativeRef.current?.getPlaybackInfo(),
26
+ }));
27
+
28
+ return <NativeView ref={nativeRef} {...props} />;
29
+ });
30
+
31
+ ExpoMpvView.displayName = 'ExpoMpvView';
32
+
33
+ export default ExpoMpvView;
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ // Reexport the native module. On web, it will be resolved to ExpoMpvModule.web.ts
2
+ // and on native platforms to ExpoMpvModule.ts
3
+ export { default } from './ExpoMpvModule';
4
+ export { default as ExpoMpvView } from './ExpoMpvView';
5
+ export * from './ExpoMpv.types';
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ // @generated by expo-module-scripts
2
+ {
3
+ "extends": "expo-module-scripts/tsconfig.base",
4
+ "compilerOptions": {
5
+ "outDir": "./build"
6
+ },
7
+ "include": ["./src"],
8
+ "exclude": ["**/__mocks__/*", "**/__tests__/*", "**/__rsc_tests__/*"]
9
+ }