Skip to content

Commit ddb39dc

Browse files
authored
Merge pull request #105 from dasisdormax/fix-android-npe
Android: Ensure methods are called only in valid MediaPlayer states
2 parents 36f31a4 + 78a789e commit ddb39dc

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

.github/workflows/gradle.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ jobs:
3030
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
3131

3232
- name: Upload artifacts
33-
uses: actions/upload-artifact@v3
33+
uses: actions/upload-artifact@v4
3434
with:
35-
name: desktop-natives
35+
name: natives-macos
3636
path: gdx-video-desktop/libs/**/*.dylib
3737
if-no-files-found: error
3838

@@ -65,9 +65,9 @@ jobs:
6565
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
6666

6767
- name: Upload artifacts
68-
uses: actions/upload-artifact@v3
68+
uses: actions/upload-artifact@v4
6969
with:
70-
name: desktop-natives
70+
name: natives-linux
7171
path: gdx-video-desktop/libs/**/*.so
7272
if-no-files-found: error
7373

@@ -98,9 +98,9 @@ jobs:
9898
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
9999

100100
- name: Upload artifacts
101-
uses: actions/upload-artifact@v3
101+
uses: actions/upload-artifact@v4
102102
with:
103-
name: desktop-natives
103+
name: natives-windows
104104
path: gdx-video-desktop/libs/**/*.dll
105105
if-no-files-found: error
106106

@@ -128,11 +128,12 @@ jobs:
128128
- name: Setup Gradle
129129
uses: gradle/gradle-build-action@v2
130130

131-
- name: Download desktop-natives artifact
132-
uses: actions/download-artifact@v3
131+
- name: Download individual natives artifacts
132+
uses: actions/download-artifact@v4
133133
with:
134-
name: desktop-natives
134+
pattern: natives-*
135135
path: gdx-video-desktop/libs
136+
merge-multiple: true
136137

137138
- name: Create JAR with natives for desktop
138139
run: ./gradlew jnigenJarNativesDesktop --info
@@ -148,7 +149,7 @@ jobs:
148149

149150
- name: Upload all output libs
150151
if: ${{ always() }}
151-
uses: actions/upload-artifact@v3
152+
uses: actions/upload-artifact@v4
152153
with:
153154
name: output-libs
154155
path: '**/build/libs/'

.github/workflows/publish_snapshot.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegMacosAll :gdx-video-desktop:jnigenBuildMacosAll
3737

3838
- name: Upload artifacts
39-
uses: actions/upload-artifact@v3
39+
uses: actions/upload-artifact@v4
4040
with:
41-
name: desktop-natives
41+
name: natives-macos
4242
path: gdx-video-desktop/libs/**/*.dylib
4343
if-no-files-found: error
4444

@@ -71,9 +71,9 @@ jobs:
7171
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegLinuxAll :gdx-video-desktop:jnigenBuildLinuxAll
7272

7373
- name: Upload artifacts
74-
uses: actions/upload-artifact@v3
74+
uses: actions/upload-artifact@v4
7575
with:
76-
name: desktop-natives
76+
name: natives-linux
7777
path: gdx-video-desktop/libs/**/*.so
7878
if-no-files-found: error
7979

@@ -104,9 +104,9 @@ jobs:
104104
run: ./gradlew :gdx-video-desktop:FFmpeg:buildFFmpegWindowsAll :gdx-video-desktop:jnigenBuildWindowsAll
105105

106106
- name: Upload artifacts
107-
uses: actions/upload-artifact@v3
107+
uses: actions/upload-artifact@v4
108108
with:
109-
name: desktop-natives
109+
name: natives-windows
110110
path: gdx-video-desktop/libs/**/*.dll
111111
if-no-files-found: error
112112

@@ -134,11 +134,12 @@ jobs:
134134
- name: Setup Gradle
135135
uses: gradle/gradle-build-action@v2
136136

137-
- name: Download desktop-natives artifact
138-
uses: actions/download-artifact@v3
137+
- name: Download individual natives artifacts
138+
uses: actions/download-artifact@v4
139139
with:
140-
name: desktop-natives
140+
pattern: natives-*
141141
path: gdx-video-desktop/libs
142+
merge-multiple: true
142143

143144
- name: Create JAR with natives for desktop
144145
run: ./gradlew jnigenJarNativesDesktop --info

gdx-video-android/src/com/badlogic/gdx/video/VideoPlayerAndroid.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public void run () {
122122

123123
VideoSizeListener sizeListener;
124124
CompletionListener completionListener;
125+
126+
private boolean currentLooping = false;
125127
private float currentVolume = 1.0f;
126128

127129
/** Used for sending mediaplayer tasks to the Main Looper */
@@ -182,6 +184,8 @@ public void run () {
182184
fbo = new FrameBuffer(Pixmap.Format.RGB888, player.getVideoWidth(), player.getVideoHeight(), false);
183185
}
184186
prepared = true;
187+
player.setVolume(currentVolume, currentVolume);
188+
player.setLooping(currentLooping);
185189
if (playRequested) {
186190
player.start();
187191
}
@@ -299,7 +303,7 @@ public boolean isBuffered () {
299303

300304
@Override
301305
public void stop () {
302-
if (player != null && player.isPlaying()) {
306+
if (player != null && isPlaying()) {
303307
player.stop();
304308
player.reset();
305309
}
@@ -315,7 +319,7 @@ public void onFrameAvailable (SurfaceTexture surfaceTexture) {
315319
@Override
316320
public void pause () {
317321
// If it is running
318-
if (prepared) {
322+
if (isPlaying()) {
319323
player.pause();
320324
}
321325
playRequested = false;
@@ -364,23 +368,34 @@ public void setOnCompletionListener (CompletionListener listener) {
364368

365369
@Override
366370
public int getVideoWidth () {
371+
if (!prepared) {
372+
return 0;
373+
}
367374
return player.getVideoWidth();
368375
}
369376

370377
@Override
371378
public int getVideoHeight () {
379+
if (!prepared) {
380+
return 0;
381+
}
372382
return player.getVideoHeight();
373383
}
374384

375385
@Override
376386
public boolean isPlaying () {
387+
if (!prepared) {
388+
return false;
389+
}
377390
return player.isPlaying();
378391
}
379392

380393
@Override
381394
public void setVolume (float volume) {
382395
currentVolume = volume;
383-
player.setVolume(volume, volume);
396+
if (prepared) {
397+
player.setVolume(volume, volume);
398+
}
384399
}
385400

386401
@Override
@@ -390,16 +405,22 @@ public float getVolume () {
390405

391406
@Override
392407
public void setLooping (boolean looping) {
393-
player.setLooping(looping);
408+
currentLooping = looping;
409+
if (prepared) {
410+
player.setLooping(looping);
411+
}
394412
}
395413

396414
@Override
397415
public boolean isLooping () {
398-
return player.isLooping();
416+
return currentLooping;
399417
}
400418

401419
@Override
402420
public int getCurrentTimestamp () {
421+
if (!prepared) {
422+
return 0;
423+
}
403424
return player.getCurrentPosition();
404425
}
405426
}

0 commit comments

Comments
 (0)