expo-libvlc-player 0.1.7 → 0.1.8

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/README.md CHANGED
@@ -113,7 +113,7 @@ The `VLCPlayerView` extends React Native `ViewProps` and implements its own:
113
113
  | ------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
114
114
  | `onBuffering` | Called after the `Buffering` player event | |
115
115
  | `onPlaying` | Called after the `Playing` player event | |
116
- | `onPaused` | Called after the `Paused` player event | |
116
+ | `onPaused` | Called after the `Paused` player event | `{ background: boolean }` |
117
117
  | `onStopped` | Called after the `Stopped` player event | |
118
118
  | `onPositionChanged` | Called after the `PositionChanged` player event | `{ position: number }` |
119
119
  | `onEnded` | Called after the `EndReached` player event | |
@@ -121,7 +121,6 @@ The `VLCPlayerView` extends React Native `ViewProps` and implements its own:
121
121
  | `onWarn` | Called after the player encounters a conflict | `{ warn: string }` |
122
122
  | `onError` | Called after the `EncounteredError` player event | `{ error: string }` |
123
123
  | `onLoad` | Called after the `Buffering` player event | `{ width: number, height: number, aspectRatio: string, duration: number, tracks: object, seekable: boolean }` |
124
- | `onBackground` | Called after the player enters the background | `{ background: boolean }` |
125
124
 
126
125
  ## Disclaimer
127
126
 
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'expo.modules.libvlcplayer'
4
- version = '0.1.6'
4
+ version = '0.1.7'
5
5
 
6
6
  def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
7
7
  apply from: expoModulesCorePlugin
@@ -35,7 +35,7 @@ android {
35
35
  namespace "expo.modules.libvlcplayer"
36
36
  defaultConfig {
37
37
  versionCode 1
38
- versionName "0.1.6"
38
+ versionName "0.1.7"
39
39
  consumerProguardFiles("proguard-rules.pro")
40
40
  }
41
41
  lintOptions {
@@ -43,6 +43,8 @@ object VlcPlayerManager {
43
43
  fun onAppForegrounded() {
44
44
  views.forEach { playerView ->
45
45
  playerView.get()?.let { view ->
46
+ view.isBackgrounded = false
47
+
46
48
  view.mediaPlayer?.let { player ->
47
49
  player.attachViews(
48
50
  view.videoLayout,
@@ -68,8 +70,6 @@ object VlcPlayerManager {
68
70
  views.forEach { playerView ->
69
71
  playerView.get()?.let { view ->
70
72
  view.isBackgrounded = true
71
- val background = mapOf("background" to view.isBackgrounded)
72
- view.onBackground(background)
73
73
 
74
74
  view.mediaPlayer?.let { player ->
75
75
  if (view.playInBackground != true && player.isPlaying()) {
@@ -17,7 +17,6 @@ private const val WARN_EVENT = "onWarn"
17
17
  private const val ERROR_EVENT = "onError"
18
18
  private const val POSITION_CHANGED_EVENT = "onPositionChanged"
19
19
  private const val LOAD_EVENT = "onLoad"
20
- private const val BACKGROUND_EVENT = "onBackground"
21
20
 
22
21
  val playerEvents = arrayOf(
23
22
  BUFFERING_EVENT,
@@ -29,8 +28,7 @@ val playerEvents = arrayOf(
29
28
  WARN_EVENT,
30
29
  ERROR_EVENT,
31
30
  POSITION_CHANGED_EVENT,
32
- LOAD_EVENT,
33
- BACKGROUND_EVENT
31
+ LOAD_EVENT
34
32
  )
35
33
 
36
34
  class VlcPlayerModule : Module() {
@@ -62,7 +62,6 @@ class VlcPlayerView(context: Context, appContext: AppContext) : ExpoView(context
62
62
  private val onError by EventDispatcher()
63
63
  private val onPositionChanged by EventDispatcher()
64
64
  private val onLoad by EventDispatcher<WritableMap>()
65
- internal val onBackground by EventDispatcher()
66
65
 
67
66
  private lateinit var audioFocusManager: AudioFocusManager
68
67
 
@@ -163,7 +162,8 @@ class VlcPlayerView(context: Context, appContext: AppContext) : ExpoView(context
163
162
  }
164
163
 
165
164
  Event.Paused -> {
166
- onPaused(mapOf())
165
+ val background = mapOf("background" to isBackgrounded)
166
+ onPaused(background)
167
167
  audioFocusManager.updateAudioFocus()
168
168
  }
169
169
 
@@ -333,9 +333,6 @@ class VlcPlayerView(context: Context, appContext: AppContext) : ExpoView(context
333
333
  }
334
334
 
335
335
  fun play() {
336
- isBackgrounded = false
337
- val background = mapOf("background" to isBackgrounded)
338
- onBackground(background)
339
336
  mediaPlayer?.play()
340
337
  }
341
338
 
@@ -22,12 +22,15 @@ class VlcPlayerManager {
22
22
  }
23
23
  }
24
24
 
25
+ func onAppForegrounded() {
26
+ for view in views.allObjects {
27
+ view.isBackgrounded = false
28
+ }
29
+ }
30
+
25
31
  func onAppBackgrounded() {
26
32
  for view in views.allObjects {
27
33
  view.isBackgrounded = true
28
- let background = ["background": view.isBackgrounded]
29
- view.onBackground(background)
30
- view.onBackground([:])
31
34
 
32
35
  guard let player = view.mediaPlayer else { continue }
33
36
 
@@ -11,7 +11,6 @@ private let warnEvent = "onWarn"
11
11
  private let errorEvent = "onError"
12
12
  private let positionChangedEvent = "onPositionChanged"
13
13
  private let loadEvent = "onLoad"
14
- private let backgroundEvent = "onBackground"
15
14
 
16
15
  let playerEvents = [
17
16
  bufferingEvent,
@@ -23,8 +22,7 @@ let playerEvents = [
23
22
  warnEvent,
24
23
  errorEvent,
25
24
  positionChangedEvent,
26
- loadEvent,
27
- backgroundEvent,
25
+ loadEvent
28
26
  ]
29
27
 
30
28
  public class VlcPlayerModule: Module {
@@ -111,6 +109,10 @@ public class VlcPlayerModule: Module {
111
109
  }
112
110
  }
113
111
 
112
+ OnAppEntersForeground {
113
+ VlcPlayerManager.shared.onAppForegrounded()
114
+ }
115
+
114
116
  OnAppEntersBackground {
115
117
  VlcPlayerManager.shared.onAppBackgrounded()
116
118
  }
@@ -37,7 +37,6 @@ class VlcPlayerView: ExpoView, VLCMediaPlayerDelegate {
37
37
  private let onError = EventDispatcher()
38
38
  private let onPositionChanged = EventDispatcher()
39
39
  private let onLoad = EventDispatcher()
40
- let onBackground = EventDispatcher()
41
40
 
42
41
  required init(appContext: AppContext? = nil) {
43
42
  super.init(appContext: appContext)
@@ -169,7 +168,8 @@ class VlcPlayerView: ExpoView, VLCMediaPlayerDelegate {
169
168
  }
170
169
  }
171
170
  case .paused:
172
- onPaused([:])
171
+ let background = ["background": isBackgrounded]
172
+ onPaused(background)
173
173
  VlcPlayerManager.shared.setAppropriateAudioSessionOrWarn()
174
174
  case .stopped:
175
175
  onStopped([:])
@@ -312,9 +312,6 @@ class VlcPlayerView: ExpoView, VLCMediaPlayerDelegate {
312
312
  }
313
313
 
314
314
  func play() {
315
- isBackgrounded = false
316
- let background = ["background": isBackgrounded]
317
- onBackground(background)
318
315
  mediaPlayer?.play()
319
316
  }
320
317
 
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ "**/*.js?(x)": "eslint --fix",
3
+ "**/*.ts?(x)": [() => "tsc --noEmit --skipLibCheck", "eslint --fix"],
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-libvlc-player",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "LibVLC Player for Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -15,12 +15,6 @@
15
15
  "open:ios": "xed example/ios",
16
16
  "open:android": "open -a \"Android Studio\" example/android"
17
17
  },
18
- "lint-staged": {
19
- "**/*.{ts,tsx,d.ts}": [
20
- "eslint --fix",
21
- "tsc --noEmit --skipLibCheck --jsx preserve"
22
- ]
23
- },
24
18
  "keywords": [
25
19
  "react-native",
26
20
  "vlc",
@@ -37,7 +37,14 @@ export type BufferingListener = () => void;
37
37
  /**
38
38
  * @hidden
39
39
  */
40
- export type PlayingPausedListener = () => void;
40
+ export type PlayingListener = () => void;
41
+
42
+ /**
43
+ * @hidden
44
+ */
45
+ export type PausedListener = (event: { nativeEvent: Paused }) => void;
46
+
47
+ export type Paused = { background: boolean };
41
48
 
42
49
  /**
43
50
  * @hidden
@@ -82,13 +89,6 @@ export type PositionChanged = { position: number };
82
89
  */
83
90
  export type LoadListener = (event: { nativeEvent: VideoInfo }) => void;
84
91
 
85
- /**
86
- * @hidden
87
- */
88
- export type BackgroundListener = (event: { nativeEvent: Background }) => void;
89
-
90
- export type Background = { background: boolean };
91
-
92
92
  export interface Track {
93
93
  id: number;
94
94
  name: string;
@@ -137,8 +137,8 @@ export interface VlcPlayerViewNativeProps {
137
137
  playInBackground?: boolean;
138
138
  autoplay?: boolean;
139
139
  onBuffering?: BufferingListener;
140
- onPlaying?: PlayingPausedListener;
141
- onPaused?: PlayingPausedListener;
140
+ onPlaying?: PlayingListener;
141
+ onPaused?: PausedListener;
142
142
  onStopped?: StoppedListener;
143
143
  onEnded?: EndedListener;
144
144
  onRepeat?: RepeatListener;
@@ -146,7 +146,6 @@ export interface VlcPlayerViewNativeProps {
146
146
  onError?: ErrorListener;
147
147
  onPositionChanged?: PositionChangedListener;
148
148
  onLoad?: LoadListener;
149
- onBackground?: BackgroundListener;
150
149
  }
151
150
 
152
151
  export type AudioMixingMode =
@@ -270,7 +269,7 @@ export interface VlcPlayerViewProps extends ViewProps {
270
269
  /**
271
270
  * Event that fires when player pauses
272
271
  */
273
- onPaused?: () => void;
272
+ onPaused?: (event: Paused) => void;
274
273
  /**
275
274
  * Event that fires when player stops
276
275
  */
@@ -299,8 +298,4 @@ export interface VlcPlayerViewProps extends ViewProps {
299
298
  * Event that fires when player loads
300
299
  */
301
300
  onLoad?: (event: VideoInfo) => void;
302
- /**
303
- * Event that fires when player enters the background
304
- */
305
- onBackground?: (event: Background) => void;
306
301
  }
@@ -5,11 +5,11 @@ import {
5
5
  VlcPlayerViewNativeProps,
6
6
  VlcPlayerViewProps,
7
7
  VLCPlayerViewRef,
8
+ type Paused,
8
9
  type Warn,
9
10
  type Error,
10
11
  type PositionChanged,
11
12
  type VideoInfo,
12
- type Background,
13
13
  } from "./VlcPlayer.types";
14
14
  import { convertNativeProps } from "./utils/props";
15
15
 
@@ -30,6 +30,12 @@ const VlcPlayerView = forwardRef<VLCPlayerViewRef, VlcPlayerViewProps>(
30
30
  loggedRenderingChildrenWarning = true;
31
31
  }
32
32
 
33
+ const onPaused = ({ nativeEvent }: { nativeEvent: Paused }) => {
34
+ if (props.onPaused) {
35
+ props.onPaused(nativeEvent);
36
+ }
37
+ };
38
+
33
39
  const onWarn = ({ nativeEvent }: { nativeEvent: Warn }) => {
34
40
  if (props.onWarn) {
35
41
  props.onWarn(nativeEvent);
@@ -58,21 +64,15 @@ const VlcPlayerView = forwardRef<VLCPlayerViewRef, VlcPlayerViewProps>(
58
64
  }
59
65
  };
60
66
 
61
- const onBackground = ({ nativeEvent }: { nativeEvent: Background }) => {
62
- if (props.onBackground) {
63
- props.onBackground(nativeEvent);
64
- }
65
- };
66
-
67
67
  return (
68
68
  <NativeView
69
69
  {...nativeProps}
70
70
  ref={ref}
71
+ onPaused={onPaused}
71
72
  onWarn={onWarn}
72
73
  onError={onError}
73
74
  onPositionChanged={onPositionChanged}
74
75
  onLoad={onLoad}
75
- onBackground={onBackground}
76
76
  />
77
77
  );
78
78
  },