- 28,932 files - Full Java source code - Smali files - Resources Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
254 lines
11 KiB
Java
254 lines
11 KiB
Java
package com.unity3d.services.ads.video;
|
|
|
|
import android.content.Context;
|
|
import android.media.AudioManager;
|
|
import android.media.MediaPlayer;
|
|
import android.widget.VideoView;
|
|
import com.unity3d.services.core.log.DeviceLog;
|
|
import com.unity3d.services.core.webview.WebViewEventCategory;
|
|
import com.unity3d.services.core.webview.bridge.IEventSender;
|
|
import com.unity3d.services.core.webview.bridge.SharedInstances;
|
|
import java.util.Timer;
|
|
import java.util.TimerTask;
|
|
|
|
/* loaded from: classes4.dex */
|
|
public class VideoPlayerView extends VideoView {
|
|
private AudioManager _audioManager;
|
|
private final IEventSender _eventSender;
|
|
private boolean _infoListenerEnabled;
|
|
private MediaPlayer _mediaPlayer;
|
|
private Timer _prepareTimer;
|
|
private int _progressEventInterval;
|
|
private Timer _videoTimer;
|
|
private String _videoUrl;
|
|
private Float _volume;
|
|
|
|
public int getProgressEventInterval() {
|
|
return this._progressEventInterval;
|
|
}
|
|
|
|
public VideoPlayerView(Context context) {
|
|
this(context, SharedInstances.INSTANCE.getWebViewEventSender());
|
|
}
|
|
|
|
public VideoPlayerView(Context context, IEventSender iEventSender) {
|
|
super(context);
|
|
this._progressEventInterval = 500;
|
|
this._mediaPlayer = null;
|
|
this._volume = null;
|
|
this._infoListenerEnabled = true;
|
|
this._audioManager = null;
|
|
this._eventSender = iEventSender;
|
|
}
|
|
|
|
private void startVideoProgressTimer() {
|
|
Timer timer = new Timer();
|
|
this._videoTimer = timer;
|
|
TimerTask timerTask = new TimerTask() { // from class: com.unity3d.services.ads.video.VideoPlayerView.1
|
|
@Override // java.util.TimerTask, java.lang.Runnable
|
|
public void run() {
|
|
boolean z;
|
|
IllegalStateException e;
|
|
try {
|
|
z = VideoPlayerView.this.isPlaying();
|
|
try {
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PROGRESS, Integer.valueOf(VideoPlayerView.this.getCurrentPosition()));
|
|
} catch (IllegalStateException e2) {
|
|
e = e2;
|
|
DeviceLog.exception("Exception while sending current position to webapp", e);
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.ILLEGAL_STATE, VideoPlayerEvent.PROGRESS, VideoPlayerView.this._videoUrl, Boolean.valueOf(z));
|
|
}
|
|
} catch (IllegalStateException e3) {
|
|
z = false;
|
|
e = e3;
|
|
}
|
|
}
|
|
};
|
|
int i = this._progressEventInterval;
|
|
timer.scheduleAtFixedRate(timerTask, i, i);
|
|
}
|
|
|
|
public void stopVideoProgressTimer() {
|
|
Timer timer = this._videoTimer;
|
|
if (timer != null) {
|
|
timer.cancel();
|
|
this._videoTimer.purge();
|
|
this._videoTimer = null;
|
|
}
|
|
}
|
|
|
|
private void startPrepareTimer(long j) {
|
|
Timer timer = new Timer();
|
|
this._prepareTimer = timer;
|
|
timer.schedule(new TimerTask() { // from class: com.unity3d.services.ads.video.VideoPlayerView.2
|
|
@Override // java.util.TimerTask, java.lang.Runnable
|
|
public void run() {
|
|
boolean z;
|
|
IllegalStateException e;
|
|
try {
|
|
z = VideoPlayerView.this.isPlaying();
|
|
if (z) {
|
|
return;
|
|
}
|
|
try {
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PREPARE_TIMEOUT, VideoPlayerView.this._videoUrl);
|
|
DeviceLog.error("Video player prepare timeout: " + VideoPlayerView.this._videoUrl);
|
|
} catch (IllegalStateException e2) {
|
|
e = e2;
|
|
DeviceLog.exception("Exception while preparing timer", e);
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.ILLEGAL_STATE, VideoPlayerEvent.PREPARE_TIMEOUT, VideoPlayerView.this._videoUrl, Boolean.valueOf(z));
|
|
}
|
|
} catch (IllegalStateException e3) {
|
|
z = false;
|
|
e = e3;
|
|
}
|
|
}
|
|
}, j);
|
|
}
|
|
|
|
public void stopPrepareTimer() {
|
|
Timer timer = this._prepareTimer;
|
|
if (timer != null) {
|
|
timer.cancel();
|
|
this._prepareTimer.purge();
|
|
this._prepareTimer = null;
|
|
}
|
|
}
|
|
|
|
public boolean prepare(String str, final float f, int i) {
|
|
DeviceLog.entered();
|
|
this._videoUrl = str;
|
|
setOnPreparedListener(new MediaPlayer.OnPreparedListener() { // from class: com.unity3d.services.ads.video.VideoPlayerView.3
|
|
@Override // android.media.MediaPlayer.OnPreparedListener
|
|
public void onPrepared(MediaPlayer mediaPlayer) {
|
|
VideoPlayerView.this.stopPrepareTimer();
|
|
if (mediaPlayer != null) {
|
|
VideoPlayerView.this._mediaPlayer = mediaPlayer;
|
|
}
|
|
VideoPlayerView.this.setVolume(Float.valueOf(f));
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PREPARED, VideoPlayerView.this._videoUrl, Integer.valueOf(mediaPlayer.getDuration()), Integer.valueOf(mediaPlayer.getVideoWidth()), Integer.valueOf(mediaPlayer.getVideoHeight()));
|
|
}
|
|
});
|
|
setOnErrorListener(new MediaPlayer.OnErrorListener() { // from class: com.unity3d.services.ads.video.VideoPlayerView.4
|
|
@Override // android.media.MediaPlayer.OnErrorListener
|
|
public boolean onError(MediaPlayer mediaPlayer, int i2, int i3) {
|
|
VideoPlayerView.this.stopPrepareTimer();
|
|
if (mediaPlayer != null) {
|
|
VideoPlayerView.this._mediaPlayer = mediaPlayer;
|
|
}
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.GENERIC_ERROR, VideoPlayerView.this._videoUrl, Integer.valueOf(i2), Integer.valueOf(i3));
|
|
VideoPlayerView.this.stopVideoProgressTimer();
|
|
return true;
|
|
}
|
|
});
|
|
setInfoListenerEnabled(this._infoListenerEnabled);
|
|
if (i > 0) {
|
|
startPrepareTimer(i);
|
|
}
|
|
try {
|
|
setAudioFocusRequest(2);
|
|
setVideoPath(this._videoUrl);
|
|
return true;
|
|
} catch (Exception e) {
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PREPARE_ERROR, this._videoUrl);
|
|
DeviceLog.exception("Error preparing video: " + this._videoUrl, e);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void play() {
|
|
DeviceLog.entered();
|
|
setOnCompletionListener(new MediaPlayer.OnCompletionListener() { // from class: com.unity3d.services.ads.video.VideoPlayerView.5
|
|
@Override // android.media.MediaPlayer.OnCompletionListener
|
|
public void onCompletion(MediaPlayer mediaPlayer) {
|
|
if (mediaPlayer != null) {
|
|
VideoPlayerView.this._mediaPlayer = mediaPlayer;
|
|
}
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.COMPLETED, VideoPlayerView.this._videoUrl);
|
|
VideoPlayerView.this.stopVideoProgressTimer();
|
|
}
|
|
});
|
|
try {
|
|
start();
|
|
stopVideoProgressTimer();
|
|
startVideoProgressTimer();
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PLAY, this._videoUrl);
|
|
} catch (IllegalStateException unused) {
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.ILLEGAL_STATE, this._videoUrl, Boolean.FALSE);
|
|
}
|
|
}
|
|
|
|
public void setInfoListenerEnabled(boolean z) {
|
|
this._infoListenerEnabled = z;
|
|
if (z) {
|
|
setOnInfoListener(new MediaPlayer.OnInfoListener() { // from class: com.unity3d.services.ads.video.VideoPlayerView.6
|
|
@Override // android.media.MediaPlayer.OnInfoListener
|
|
public boolean onInfo(MediaPlayer mediaPlayer, int i, int i2) {
|
|
VideoPlayerView.this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.INFO, VideoPlayerView.this._videoUrl, Integer.valueOf(i), Integer.valueOf(i2));
|
|
return true;
|
|
}
|
|
});
|
|
} else {
|
|
setOnInfoListener(null);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.VideoView, android.widget.MediaController.MediaPlayerControl
|
|
public void pause() {
|
|
try {
|
|
super.pause();
|
|
setAudioFocusRequest(0);
|
|
stopVideoProgressTimer();
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PAUSE, this._videoUrl);
|
|
} catch (Exception e) {
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.PAUSE_ERROR, this._videoUrl);
|
|
DeviceLog.exception("Error pausing video", e);
|
|
}
|
|
}
|
|
|
|
@Override // android.widget.VideoView, android.widget.MediaController.MediaPlayerControl
|
|
public void seekTo(int i) {
|
|
try {
|
|
super.seekTo(i);
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.SEEKTO, this._videoUrl);
|
|
} catch (Exception e) {
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.SEEKTO_ERROR, this._videoUrl);
|
|
DeviceLog.exception("Error seeking video", e);
|
|
}
|
|
}
|
|
|
|
public void stop() {
|
|
stopPlayback();
|
|
stopVideoProgressTimer();
|
|
setAudioFocusRequest(0);
|
|
this._eventSender.sendEvent(WebViewEventCategory.VIDEOPLAYER, VideoPlayerEvent.STOP, this._videoUrl);
|
|
}
|
|
|
|
public float getVolume() {
|
|
return this._volume.floatValue();
|
|
}
|
|
|
|
public void setVolume(Float f) {
|
|
try {
|
|
this._mediaPlayer.setVolume(f.floatValue(), f.floatValue());
|
|
this._volume = f;
|
|
} catch (Exception e) {
|
|
DeviceLog.exception("MediaPlayer generic error", e);
|
|
}
|
|
}
|
|
|
|
public void setProgressEventInterval(int i) {
|
|
this._progressEventInterval = i;
|
|
if (this._videoTimer != null) {
|
|
stopVideoProgressTimer();
|
|
startVideoProgressTimer();
|
|
}
|
|
}
|
|
|
|
public int[] getVideoViewRectangle() {
|
|
int[] iArr = new int[2];
|
|
getLocationInWindow(iArr);
|
|
return new int[]{iArr[0], iArr[1], getMeasuredWidth(), getMeasuredHeight()};
|
|
}
|
|
}
|