use of org.telegram.ui.Components.PipRoundVideoView in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method onConfigurationChanged.
@Override
public void onConfigurationChanged(Configuration newConfig) {
AndroidUtilities.checkDisplaySize(this, newConfig);
super.onConfigurationChanged(newConfig);
checkLayout();
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
if (pipRoundVideoView != null) {
pipRoundVideoView.onConfigurationChanged();
}
EmbedBottomSheet embedBottomSheet = EmbedBottomSheet.getInstance();
if (embedBottomSheet != null) {
embedBottomSheet.onConfigurationChanged(newConfig);
}
PhotoViewer photoViewer = PhotoViewer.getPipInstance();
if (photoViewer != null) {
photoViewer.onConfigurationChanged(newConfig);
}
ThemeEditorView editorView = ThemeEditorView.getInstance();
if (editorView != null) {
editorView.onConfigurationChanged();
}
if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
Theme.checkAutoNightThemeConditions();
}
}
use of org.telegram.ui.Components.PipRoundVideoView in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaController method playMessage.
public boolean playMessage(final MessageObject messageObject) {
if (messageObject == null) {
return false;
}
if ((audioPlayer != null || videoPlayer != null) && isSamePlayingMessage(messageObject)) {
if (isPaused) {
resumeAudio(messageObject);
}
if (!SharedConfig.raiseToSpeak) {
startRaiseToEarSensors(raiseChat);
}
return true;
}
if (!messageObject.isOut() && messageObject.isContentUnread()) {
MessagesController.getInstance(messageObject.currentAccount).markMessageContentAsRead(messageObject);
}
boolean notify = !playMusicAgain;
if (playingMessageObject != null) {
notify = false;
if (!playMusicAgain) {
playingMessageObject.resetPlayingProgress();
NotificationCenter.getInstance(playingMessageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, playingMessageObject.getId(), 0);
}
}
cleanupPlayer(notify, false);
shouldSavePositionForCurrentAudio = null;
lastSaveTime = 0;
playMusicAgain = false;
seekToProgressPending = 0;
File file = null;
boolean exists = false;
if (messageObject.messageOwner.attachPath != null && messageObject.messageOwner.attachPath.length() > 0) {
file = new File(messageObject.messageOwner.attachPath);
exists = file.exists();
if (!exists) {
file = null;
}
}
final File cacheFile = file != null ? file : FileLoader.getPathToMessage(messageObject.messageOwner);
boolean canStream = SharedConfig.streamMedia && (messageObject.isMusic() || messageObject.isRoundVideo() || messageObject.isVideo() && messageObject.canStreamVideo()) && !DialogObject.isEncryptedDialog(messageObject.getDialogId());
if (cacheFile != file && !(exists = cacheFile.exists()) && !canStream) {
FileLoader.getInstance(messageObject.currentAccount).loadFile(messageObject.getDocument(), messageObject, 0, 0);
downloadingCurrentMessage = true;
isPaused = false;
lastProgress = 0;
audioInfo = null;
playingMessageObject = messageObject;
if (playingMessageObject.isMusic()) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
try {
/*if (Build.VERSION.SDK_INT >= 26) {
ApplicationLoader.applicationContext.startForegroundService(intent);
} else {*/
ApplicationLoader.applicationContext.startService(intent);
// }
} catch (Throwable e) {
FileLog.e(e);
}
} else {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
NotificationCenter.getInstance(playingMessageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingPlayStateChanged, playingMessageObject.getId());
return true;
} else {
downloadingCurrentMessage = false;
}
if (messageObject.isMusic()) {
checkIsNextMusicFileDownloaded(messageObject.currentAccount);
} else {
checkIsNextVoiceFileDownloaded(messageObject.currentAccount);
}
if (currentAspectRatioFrameLayout != null) {
isDrawingWasReady = false;
currentAspectRatioFrameLayout.setDrawingReady(false);
}
boolean isVideo = messageObject.isVideo();
if (messageObject.isRoundVideo() || isVideo) {
FileLoader.getInstance(messageObject.currentAccount).setLoadingVideoForPlayer(messageObject.getDocument(), true);
playerWasReady = false;
boolean destroyAtEnd = !isVideo || messageObject.messageOwner.peer_id.channel_id == 0 && messageObject.audioProgress <= 0.1f;
int[] playCount = isVideo && messageObject.getDuration() <= 30 ? new int[] { 1 } : null;
clearPlaylist();
videoPlayer = new VideoPlayer();
int tag = ++playerNum;
videoPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
if (tag != playerNum) {
return;
}
updateVideoState(messageObject, playCount, destroyAtEnd, playWhenReady, playbackState);
}
@Override
public void onError(VideoPlayer player, Exception e) {
FileLog.e(e);
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
currentAspectRatioFrameLayoutRotation = unappliedRotationDegrees;
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
int temp = width;
width = height;
height = temp;
}
currentAspectRatioFrameLayoutRatio = height == 0 ? 1 : (width * pixelWidthHeightRatio) / height;
if (currentAspectRatioFrameLayout != null) {
currentAspectRatioFrameLayout.setAspectRatio(currentAspectRatioFrameLayoutRatio, currentAspectRatioFrameLayoutRotation);
}
}
@Override
public void onRenderedFirstFrame() {
if (currentAspectRatioFrameLayout != null && !currentAspectRatioFrameLayout.isDrawingReady()) {
isDrawingWasReady = true;
currentAspectRatioFrameLayout.setDrawingReady(true);
currentTextureViewContainer.setTag(1);
// if (currentTextureViewContainer != null && currentTextureViewContainer.getVisibility() != View.VISIBLE) {
// currentTextureViewContainer.setVisibility(View.VISIBLE);
// }
}
}
@Override
public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
if (videoPlayer == null) {
return false;
}
if (pipSwitchingState == 2) {
if (currentAspectRatioFrameLayout != null) {
if (isDrawingWasReady) {
currentAspectRatioFrameLayout.setDrawingReady(true);
}
if (currentAspectRatioFrameLayout.getParent() == null) {
currentTextureViewContainer.addView(currentAspectRatioFrameLayout);
}
if (currentTextureView.getSurfaceTexture() != surfaceTexture) {
currentTextureView.setSurfaceTexture(surfaceTexture);
}
videoPlayer.setTextureView(currentTextureView);
}
pipSwitchingState = 0;
return true;
} else if (pipSwitchingState == 1) {
if (baseActivity != null) {
if (pipRoundVideoView == null) {
try {
pipRoundVideoView = new PipRoundVideoView();
pipRoundVideoView.show(baseActivity, () -> cleanupPlayer(true, true));
} catch (Exception e) {
pipRoundVideoView = null;
}
}
if (pipRoundVideoView != null) {
if (pipRoundVideoView.getTextureView().getSurfaceTexture() != surfaceTexture) {
pipRoundVideoView.getTextureView().setSurfaceTexture(surfaceTexture);
}
videoPlayer.setTextureView(pipRoundVideoView.getTextureView());
}
}
pipSwitchingState = 0;
return true;
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isInjectingVideoPlayer()) {
PhotoViewer.getInstance().injectVideoPlayerSurface(surfaceTexture);
return true;
}
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
});
currentAspectRatioFrameLayoutReady = false;
if (pipRoundVideoView != null || !MessagesController.getInstance(messageObject.currentAccount).isDialogVisible(messageObject.getDialogId(), messageObject.scheduled)) {
if (pipRoundVideoView == null) {
try {
pipRoundVideoView = new PipRoundVideoView();
pipRoundVideoView.show(baseActivity, () -> cleanupPlayer(true, true));
} catch (Exception e) {
pipRoundVideoView = null;
}
}
if (pipRoundVideoView != null) {
videoPlayer.setTextureView(pipRoundVideoView.getTextureView());
}
} else if (currentTextureView != null) {
videoPlayer.setTextureView(currentTextureView);
}
if (exists) {
if (!messageObject.mediaExists && cacheFile != file) {
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.fileLoaded, FileLoader.getAttachFileName(messageObject.getDocument()), cacheFile));
}
videoPlayer.preparePlayer(Uri.fromFile(cacheFile), "other");
} else {
try {
int reference = FileLoader.getInstance(messageObject.currentAccount).getFileReference(messageObject);
TLRPC.Document document = messageObject.getDocument();
String params = "?account=" + messageObject.currentAccount + "&id=" + document.id + "&hash=" + document.access_hash + "&dc=" + document.dc_id + "&size=" + document.size + "&mime=" + URLEncoder.encode(document.mime_type, "UTF-8") + "&rid=" + reference + "&name=" + URLEncoder.encode(FileLoader.getDocumentFileName(document), "UTF-8") + "&reference=" + Utilities.bytesToHex(document.file_reference != null ? document.file_reference : new byte[0]);
Uri uri = Uri.parse("tg://" + messageObject.getFileName() + params);
videoPlayer.preparePlayer(uri, "other");
} catch (Exception e) {
FileLog.e(e);
}
}
if (messageObject.isRoundVideo()) {
videoPlayer.setStreamType(useFrontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);
if (Math.abs(currentPlaybackSpeed - 1.0f) > 0.001f) {
videoPlayer.setPlaybackSpeed(currentPlaybackSpeed);
}
if (messageObject.forceSeekTo >= 0) {
messageObject.audioProgress = seekToProgressPending = messageObject.forceSeekTo;
messageObject.forceSeekTo = -1;
}
} else {
videoPlayer.setStreamType(AudioManager.STREAM_MUSIC);
}
} else {
if (pipRoundVideoView != null) {
pipRoundVideoView.close(true);
pipRoundVideoView = null;
}
try {
audioPlayer = new VideoPlayer();
int tag = ++playerNum;
audioPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
if (tag != playerNum) {
return;
}
if (playbackState == ExoPlayer.STATE_ENDED || (playbackState == ExoPlayer.STATE_IDLE || playbackState == ExoPlayer.STATE_BUFFERING) && playWhenReady && messageObject.audioProgress >= 0.999f) {
messageObject.audioProgress = 1f;
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, messageObject.getId(), 0);
if (!playlist.isEmpty() && (playlist.size() > 1 || !messageObject.isVoice())) {
playNextMessageWithoutOrder(true);
} else {
cleanupPlayer(true, true, messageObject.isVoice(), false);
}
} else if (audioPlayer != null && seekToProgressPending != 0 && (playbackState == ExoPlayer.STATE_READY || playbackState == ExoPlayer.STATE_IDLE)) {
int seekTo = (int) (audioPlayer.getDuration() * seekToProgressPending);
audioPlayer.seekTo(seekTo);
lastProgress = seekTo;
seekToProgressPending = 0;
}
}
@Override
public void onError(VideoPlayer player, Exception e) {
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
}
@Override
public void onRenderedFirstFrame() {
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
@Override
public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
return false;
}
});
audioPlayer.setAudioVisualizerDelegate(new VideoPlayer.AudioVisualizerDelegate() {
@Override
public void onVisualizerUpdate(boolean playing, boolean animate, float[] values) {
Theme.getCurrentAudiVisualizerDrawable().setWaveform(playing, animate, values);
}
@Override
public boolean needUpdate() {
return Theme.getCurrentAudiVisualizerDrawable().getParentView() != null;
}
});
if (exists) {
if (!messageObject.mediaExists && cacheFile != file) {
AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.fileLoaded, FileLoader.getAttachFileName(messageObject.getDocument()), cacheFile));
}
audioPlayer.preparePlayer(Uri.fromFile(cacheFile), "other");
isStreamingCurrentAudio = false;
} else {
int reference = FileLoader.getInstance(messageObject.currentAccount).getFileReference(messageObject);
TLRPC.Document document = messageObject.getDocument();
String params = "?account=" + messageObject.currentAccount + "&id=" + document.id + "&hash=" + document.access_hash + "&dc=" + document.dc_id + "&size=" + document.size + "&mime=" + URLEncoder.encode(document.mime_type, "UTF-8") + "&rid=" + reference + "&name=" + URLEncoder.encode(FileLoader.getDocumentFileName(document), "UTF-8") + "&reference=" + Utilities.bytesToHex(document.file_reference != null ? document.file_reference : new byte[0]);
Uri uri = Uri.parse("tg://" + messageObject.getFileName() + params);
audioPlayer.preparePlayer(uri, "other");
isStreamingCurrentAudio = true;
}
if (messageObject.isVoice()) {
String name = messageObject.getFileName();
if (name != null && messageObject.getDuration() >= 5 * 60) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", Activity.MODE_PRIVATE);
float pos = preferences.getFloat(name, -1);
if (pos > 0 && pos < 0.99f) {
messageObject.audioProgress = seekToProgressPending = pos;
}
shouldSavePositionForCurrentAudio = name;
}
if (Math.abs(currentPlaybackSpeed - 1.0f) > 0.001f) {
audioPlayer.setPlaybackSpeed(currentPlaybackSpeed);
}
audioInfo = null;
clearPlaylist();
} else {
try {
audioInfo = AudioInfo.getAudioInfo(cacheFile);
} catch (Exception e) {
FileLog.e(e);
}
String name = messageObject.getFileName();
if (!TextUtils.isEmpty(name) && messageObject.getDuration() >= 10 * 60) {
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("media_saved_pos", Activity.MODE_PRIVATE);
float pos = preferences.getFloat(name, -1);
if (pos > 0 && pos < 0.999f) {
messageObject.audioProgress = seekToProgressPending = pos;
}
shouldSavePositionForCurrentAudio = name;
if (Math.abs(currentMusicPlaybackSpeed - 1.0f) > 0.001f) {
audioPlayer.setPlaybackSpeed(currentMusicPlaybackSpeed);
}
}
}
if (messageObject.forceSeekTo >= 0) {
messageObject.audioProgress = seekToProgressPending = messageObject.forceSeekTo;
messageObject.forceSeekTo = -1;
}
audioPlayer.setStreamType(useFrontSpeaker ? AudioManager.STREAM_VOICE_CALL : AudioManager.STREAM_MUSIC);
audioPlayer.play();
if (!messageObject.isVoice()) {
if (audioVolumeAnimator != null) {
audioVolumeAnimator.removeAllListeners();
audioVolumeAnimator.cancel();
}
audioVolumeAnimator = ValueAnimator.ofFloat(audioVolume, 1f);
audioVolumeAnimator.addUpdateListener(audioVolumeUpdateListener);
audioVolumeAnimator.setDuration(300);
audioVolumeAnimator.start();
} else {
audioVolume = 1f;
setPlayerVolume();
}
} catch (Exception e) {
FileLog.e(e);
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingPlayStateChanged, playingMessageObject != null ? playingMessageObject.getId() : 0);
if (audioPlayer != null) {
audioPlayer.releasePlayer(true);
audioPlayer = null;
Theme.unrefAudioVisualizeDrawable(playingMessageObject);
isPaused = false;
playingMessageObject = null;
downloadingCurrentMessage = false;
}
return false;
}
}
checkAudioFocus(messageObject);
setPlayerVolume();
isPaused = false;
lastProgress = 0;
playingMessageObject = messageObject;
if (!SharedConfig.raiseToSpeak) {
startRaiseToEarSensors(raiseChat);
}
if (!ApplicationLoader.mainInterfacePaused && proximityWakeLock != null && !proximityWakeLock.isHeld() && (playingMessageObject.isVoice() || playingMessageObject.isRoundVideo())) {
proximityWakeLock.acquire();
}
startProgressTimer(playingMessageObject);
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingDidStart, messageObject);
if (videoPlayer != null) {
try {
if (playingMessageObject.audioProgress != 0) {
long duration = videoPlayer.getDuration();
if (duration == C.TIME_UNSET) {
duration = (long) playingMessageObject.getDuration() * 1000;
}
int seekTo = (int) (duration * playingMessageObject.audioProgress);
if (playingMessageObject.audioProgressMs != 0) {
seekTo = playingMessageObject.audioProgressMs;
playingMessageObject.audioProgressMs = 0;
}
videoPlayer.seekTo(seekTo);
}
} catch (Exception e2) {
playingMessageObject.audioProgress = 0;
playingMessageObject.audioProgressSec = 0;
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, playingMessageObject.getId(), 0);
FileLog.e(e2);
}
videoPlayer.play();
} else if (audioPlayer != null) {
try {
if (playingMessageObject.audioProgress != 0) {
long duration = audioPlayer.getDuration();
if (duration == C.TIME_UNSET) {
duration = (long) playingMessageObject.getDuration() * 1000;
}
int seekTo = (int) (duration * playingMessageObject.audioProgress);
audioPlayer.seekTo(seekTo);
}
} catch (Exception e2) {
playingMessageObject.resetPlayingProgress();
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, playingMessageObject.getId(), 0);
FileLog.e(e2);
}
}
if (playingMessageObject != null && playingMessageObject.isMusic()) {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
try {
/*if (Build.VERSION.SDK_INT >= 26) {
ApplicationLoader.applicationContext.startForegroundService(intent);
} else {*/
ApplicationLoader.applicationContext.startService(intent);
// }
} catch (Throwable e) {
FileLog.e(e);
}
} else {
Intent intent = new Intent(ApplicationLoader.applicationContext, MusicPlayerService.class);
ApplicationLoader.applicationContext.stopService(intent);
}
return true;
}
use of org.telegram.ui.Components.PipRoundVideoView in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method onResume.
@Override
protected void onResume() {
super.onResume();
if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
Theme.checkAutoNightThemeConditions();
}
checkWasMutedByAdmin(true);
// FileLog.d("UI resume time = " + (SystemClock.elapsedRealtime() - ApplicationLoader.startTime));
NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.startAllHeavyOperations, 4096);
MediaController.getInstance().setFeedbackView(actionBarLayout, true);
ApplicationLoader.mainInterfacePaused = false;
showLanguageAlert(false);
Utilities.stageQueue.postRunnable(() -> {
ApplicationLoader.mainInterfacePausedStageQueue = false;
ApplicationLoader.mainInterfacePausedStageQueueTime = System.currentTimeMillis();
});
checkFreeDiscSpace();
MediaController.checkGallery();
onPasscodeResume();
if (passcodeView == null || passcodeView.getVisibility() != View.VISIBLE) {
actionBarLayout.onResume();
if (AndroidUtilities.isTablet()) {
rightActionBarLayout.onResume();
layersActionBarLayout.onResume();
}
} else {
actionBarLayout.dismissDialogs();
if (AndroidUtilities.isTablet()) {
rightActionBarLayout.dismissDialogs();
layersActionBarLayout.dismissDialogs();
}
passcodeView.onResume();
}
ConnectionsManager.getInstance(currentAccount).setAppPaused(false, false);
updateCurrentConnectionState(currentAccount);
if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
PhotoViewer.getInstance().onResume();
}
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
if (pipRoundVideoView != null && MediaController.getInstance().isMessagePaused()) {
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject != null) {
MediaController.getInstance().seekToProgress(messageObject, messageObject.audioProgress);
}
}
if (UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService != null) {
showTosActivity(UserConfig.selectedAccount, UserConfig.getInstance(UserConfig.selectedAccount).unacceptedTermsOfService);
} else if (SharedConfig.pendingAppUpdate != null && SharedConfig.pendingAppUpdate.can_not_skip) {
showUpdateActivity(UserConfig.selectedAccount, SharedConfig.pendingAppUpdate, true);
}
checkAppUpdate(false);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ApplicationLoader.canDrawOverlays = Settings.canDrawOverlays(this);
}
if (VoIPFragment.getInstance() != null) {
VoIPFragment.onResume();
}
}
use of org.telegram.ui.Components.PipRoundVideoView in project Telegram-FOSS by Telegram-FOSS-Team.
the class LaunchActivity method onDestroy.
@Override
protected void onDestroy() {
if (PhotoViewer.getPipInstance() != null) {
PhotoViewer.getPipInstance().destroyPhotoViewer();
}
if (PhotoViewer.hasInstance()) {
PhotoViewer.getInstance().destroyPhotoViewer();
}
if (SecretMediaViewer.hasInstance()) {
SecretMediaViewer.getInstance().destroyPhotoViewer();
}
if (ArticleViewer.hasInstance()) {
ArticleViewer.getInstance().destroyArticleViewer();
}
if (ContentPreviewViewer.hasInstance()) {
ContentPreviewViewer.getInstance().destroy();
}
if (GroupCallActivity.groupCallInstance != null) {
GroupCallActivity.groupCallInstance.dismissInternal();
}
PipRoundVideoView pipRoundVideoView = PipRoundVideoView.getInstance();
MediaController.getInstance().setBaseActivity(this, false);
MediaController.getInstance().setFeedbackView(actionBarLayout, false);
if (pipRoundVideoView != null) {
pipRoundVideoView.close(false);
}
Theme.destroyResources();
EmbedBottomSheet embedBottomSheet = EmbedBottomSheet.getInstance();
if (embedBottomSheet != null) {
embedBottomSheet.destroy();
}
ThemeEditorView editorView = ThemeEditorView.getInstance();
if (editorView != null) {
editorView.destroy();
}
try {
if (visibleDialog != null) {
visibleDialog.dismiss();
visibleDialog = null;
}
} catch (Exception e) {
FileLog.e(e);
}
try {
if (onGlobalLayoutListener != null) {
final View view = getWindow().getDecorView().getRootView();
view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
}
} catch (Exception e) {
FileLog.e(e);
}
super.onDestroy();
onFinish();
}
use of org.telegram.ui.Components.PipRoundVideoView in project Telegram-FOSS by Telegram-FOSS-Team.
the class MediaController method injectVideoPlayer.
public void injectVideoPlayer(VideoPlayer player, MessageObject messageObject) {
if (player == null || messageObject == null) {
return;
}
FileLoader.getInstance(messageObject.currentAccount).setLoadingVideoForPlayer(messageObject.getDocument(), true);
playerWasReady = false;
boolean destroyAtEnd = true;
int[] playCount = null;
clearPlaylist();
videoPlayer = player;
playingMessageObject = messageObject;
int tag = ++playerNum;
videoPlayer.setDelegate(new VideoPlayer.VideoPlayerDelegate() {
@Override
public void onStateChanged(boolean playWhenReady, int playbackState) {
if (tag != playerNum) {
return;
}
updateVideoState(messageObject, playCount, destroyAtEnd, playWhenReady, playbackState);
}
@Override
public void onError(VideoPlayer player, Exception e) {
FileLog.e(e);
}
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
currentAspectRatioFrameLayoutRotation = unappliedRotationDegrees;
if (unappliedRotationDegrees == 90 || unappliedRotationDegrees == 270) {
int temp = width;
width = height;
height = temp;
}
currentAspectRatioFrameLayoutRatio = height == 0 ? 1 : (width * pixelWidthHeightRatio) / height;
if (currentAspectRatioFrameLayout != null) {
currentAspectRatioFrameLayout.setAspectRatio(currentAspectRatioFrameLayoutRatio, currentAspectRatioFrameLayoutRotation);
}
}
@Override
public void onRenderedFirstFrame() {
if (currentAspectRatioFrameLayout != null && !currentAspectRatioFrameLayout.isDrawingReady()) {
isDrawingWasReady = true;
currentAspectRatioFrameLayout.setDrawingReady(true);
currentTextureViewContainer.setTag(1);
}
}
@Override
public boolean onSurfaceDestroyed(SurfaceTexture surfaceTexture) {
if (videoPlayer == null) {
return false;
}
if (pipSwitchingState == 2) {
if (currentAspectRatioFrameLayout != null) {
if (isDrawingWasReady) {
currentAspectRatioFrameLayout.setDrawingReady(true);
}
if (currentAspectRatioFrameLayout.getParent() == null) {
currentTextureViewContainer.addView(currentAspectRatioFrameLayout);
}
if (currentTextureView.getSurfaceTexture() != surfaceTexture) {
currentTextureView.setSurfaceTexture(surfaceTexture);
}
videoPlayer.setTextureView(currentTextureView);
}
pipSwitchingState = 0;
return true;
} else if (pipSwitchingState == 1) {
if (baseActivity != null) {
if (pipRoundVideoView == null) {
try {
pipRoundVideoView = new PipRoundVideoView();
pipRoundVideoView.show(baseActivity, () -> cleanupPlayer(true, true));
} catch (Exception e) {
pipRoundVideoView = null;
}
}
if (pipRoundVideoView != null) {
if (pipRoundVideoView.getTextureView().getSurfaceTexture() != surfaceTexture) {
pipRoundVideoView.getTextureView().setSurfaceTexture(surfaceTexture);
}
videoPlayer.setTextureView(pipRoundVideoView.getTextureView());
}
}
pipSwitchingState = 0;
return true;
} else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isInjectingVideoPlayer()) {
PhotoViewer.getInstance().injectVideoPlayerSurface(surfaceTexture);
return true;
}
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
});
currentAspectRatioFrameLayoutReady = false;
if (currentTextureView != null) {
videoPlayer.setTextureView(currentTextureView);
}
checkAudioFocus(messageObject);
setPlayerVolume();
isPaused = false;
lastProgress = 0;
playingMessageObject = messageObject;
if (!SharedConfig.raiseToSpeak) {
startRaiseToEarSensors(raiseChat);
}
startProgressTimer(playingMessageObject);
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingDidStart, messageObject);
/*try {
if (playingMessageObject.audioProgress != 0) {
long duration = videoPlayer.getDuration();
if (duration == C.TIME_UNSET) {
duration = (long) playingMessageObject.getDuration() * 1000;
}
int seekTo = (int) (duration * playingMessageObject.audioProgress);
if (playingMessageObject.audioProgressMs != 0) {
seekTo = playingMessageObject.audioProgressMs;
playingMessageObject.audioProgressMs = 0;
}
videoPlayer.seekTo(seekTo);
}
} catch (Exception e2) {
playingMessageObject.audioProgress = 0;
playingMessageObject.audioProgressSec = 0;
NotificationCenter.getInstance(messageObject.currentAccount).postNotificationName(NotificationCenter.messagePlayingProgressDidChanged, playingMessageObject.getId(), 0);
FileLog.e(e2);
}*/
}
Aggregations