Search in sources :

Example 1 with AudioPlayerCell

use of org.telegram.ui.Cells.AudioPlayerCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class AudioPlayerAlert method didReceivedNotification.

@Override
public void didReceivedNotification(int id, int account, Object... args) {
    if (id == NotificationCenter.messagePlayingDidStart || id == NotificationCenter.messagePlayingPlayStateChanged || id == NotificationCenter.messagePlayingDidReset) {
        updateTitle(id == NotificationCenter.messagePlayingDidReset && (Boolean) args[1]);
        if (id == NotificationCenter.messagePlayingDidReset || id == NotificationCenter.messagePlayingPlayStateChanged) {
            int count = listView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = listView.getChildAt(a);
                if (view instanceof AudioPlayerCell) {
                    AudioPlayerCell cell = (AudioPlayerCell) view;
                    MessageObject messageObject = cell.getMessageObject();
                    if (messageObject != null && (messageObject.isVoice() || messageObject.isMusic())) {
                        cell.updateButtonState(false, true);
                    }
                }
            }
            if (id == NotificationCenter.messagePlayingPlayStateChanged) {
                if (MediaController.getInstance().getPlayingMessageObject() != null) {
                    if (MediaController.getInstance().isMessagePaused()) {
                        startForwardRewindingSeek();
                    } else if (rewindingState == 1 && rewindingProgress != -1f) {
                        AndroidUtilities.cancelRunOnUIThread(forwardSeek);
                        lastUpdateRewindingPlayerTime = 0;
                        forwardSeek.run();
                        rewindingProgress = -1f;
                    }
                }
            }
        } else {
            MessageObject messageObject = (MessageObject) args[0];
            if (messageObject.eventId != 0) {
                return;
            }
            int count = listView.getChildCount();
            for (int a = 0; a < count; a++) {
                View view = listView.getChildAt(a);
                if (view instanceof AudioPlayerCell) {
                    AudioPlayerCell cell = (AudioPlayerCell) view;
                    MessageObject messageObject1 = cell.getMessageObject();
                    if (messageObject1 != null && (messageObject1.isVoice() || messageObject1.isMusic())) {
                        cell.updateButtonState(false, true);
                    }
                }
            }
        }
    } else if (id == NotificationCenter.messagePlayingProgressDidChanged) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (messageObject != null && messageObject.isMusic()) {
            updateProgress(messageObject);
        }
    } else if (id == NotificationCenter.musicDidLoad) {
        playlist = MediaController.getInstance().getPlaylist();
        listAdapter.notifyDataSetChanged();
    } else if (id == NotificationCenter.moreMusicDidLoad) {
        playlist = MediaController.getInstance().getPlaylist();
        listAdapter.notifyDataSetChanged();
        if (SharedConfig.playOrderReversed) {
            listView.stopScroll();
            int addedCount = (Integer) args[0];
            int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
            int position = layoutManager.findLastVisibleItemPosition();
            if (position != RecyclerView.NO_POSITION) {
                View firstVisView = layoutManager.findViewByPosition(position);
                int offset = firstVisView == null ? 0 : firstVisView.getTop();
                layoutManager.scrollToPositionWithOffset(position + addedCount, offset);
            }
        }
    } else if (id == NotificationCenter.fileLoaded) {
        String name = (String) args[0];
        if (name.equals(currentFile)) {
            updateTitle(false);
            currentAudioFinishedLoading = true;
        }
    } else if (id == NotificationCenter.fileLoadProgressChanged) {
        String name = (String) args[0];
        if (name.equals(currentFile)) {
            MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
            if (messageObject == null) {
                return;
            }
            Long loadedSize = (Long) args[1];
            Long totalSize = (Long) args[2];
            float bufferedProgress;
            if (currentAudioFinishedLoading) {
                bufferedProgress = 1.0f;
            } else {
                long newTime = SystemClock.elapsedRealtime();
                if (Math.abs(newTime - lastBufferedPositionCheck) >= 500) {
                    bufferedProgress = MediaController.getInstance().isStreamingCurrentAudio() ? FileLoader.getInstance(currentAccount).getBufferedProgressFromPosition(messageObject.audioProgress, currentFile) : 1.0f;
                    lastBufferedPositionCheck = newTime;
                } else {
                    bufferedProgress = -1;
                }
            }
            if (bufferedProgress != -1) {
                seekBarView.setBufferedProgress(bufferedProgress);
            }
        }
    }
}
Also used : AudioPlayerCell(org.telegram.ui.Cells.AudioPlayerCell) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 MessageObject (org.telegram.messenger.MessageObject)1 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)1 AudioPlayerCell (org.telegram.ui.Cells.AudioPlayerCell)1