public void updateButtonState(boolean animated) { if (currentMessageObject == null) { return; } if (currentMessageObject.isOut() && currentMessageObject.isSending()) { MediaController.getInstance() .addLoadingFileObserver(currentMessageObject.messageOwner.attachPath, this); buttonState = 4; radialProgress.setBackground(getDrawableForCurrentState(), true, animated); Float progress = ImageLoader.getInstance().getFileProgress(currentMessageObject.messageOwner.attachPath); if (progress == null && SendMessagesHelper.getInstance().isSendingMessage(currentMessageObject.getId())) { progress = 1.0f; } radialProgress.setProgress(progress != null ? progress : 0, false); } else { File cacheFile = null; if (currentMessageObject.messageOwner.attachPath != null && currentMessageObject.messageOwner.attachPath.length() > 0) { cacheFile = new File(currentMessageObject.messageOwner.attachPath); if (!cacheFile.exists()) { cacheFile = null; } } if (cacheFile == null) { cacheFile = FileLoader.getPathToMessage(currentMessageObject.messageOwner); } if (cacheFile.exists()) { MediaController.getInstance().removeLoadingFileObserver(this); boolean playing = MediaController.getInstance().isPlayingAudio(currentMessageObject); if (!playing || playing && MediaController.getInstance().isAudioPaused()) { buttonState = 0; } else { buttonState = 1; } radialProgress.setProgress(0, animated); radialProgress.setBackground(getDrawableForCurrentState(), false, animated); } else { String fileName = currentMessageObject.getFileName(); MediaController.getInstance().addLoadingFileObserver(fileName, this); if (!FileLoader.getInstance().isLoadingFile(fileName)) { buttonState = 2; radialProgress.setProgress(0, animated); radialProgress.setBackground(getDrawableForCurrentState(), false, animated); } else { buttonState = 3; Float progress = ImageLoader.getInstance().getFileProgress(fileName); if (progress != null) { radialProgress.setProgress(progress, animated); } else { radialProgress.setProgress(0, animated); } radialProgress.setBackground(getDrawableForCurrentState(), true, animated); } } } updateProgress(); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (currentMessageObject == null) { return; } if (currentMessageObject.isOutOwner()) { timePaint.setColor(theme.ChatMusicCell_timePaint_color); } else { timePaint.setColor(theme.ChatMusicCell_timePaint_color_2); } radialProgress.draw(canvas); canvas.save(); canvas.translate(timeX + titleX, AndroidUtilities.dp(12) + namesOffset); titleLayout.draw(canvas); canvas.restore(); canvas.save(); if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) { canvas.translate(seekBarX, seekBarY); seekBar.draw(canvas); } else { canvas.translate(timeX + authorX, AndroidUtilities.dp(32) + namesOffset); authorLayout.draw(canvas); } canvas.restore(); canvas.save(); canvas.translate(timeX, AndroidUtilities.dp(52) + namesOffset); timeLayout.draw(canvas); canvas.restore(); }
public void updateProgress() { if (currentMessageObject == null) { return; } if (!seekBar.isDragging()) { seekBar.setProgress(currentMessageObject.audioProgress); } int duration = 0; int currentProgress = 0; for (TLRPC.DocumentAttribute attribute : currentMessageObject.messageOwner.media.document.attributes) { if (attribute instanceof TLRPC.TL_documentAttributeAudio) { duration = attribute.duration; break; } } if (MediaController.getInstance().isPlayingAudio(currentMessageObject)) { currentProgress = currentMessageObject.audioProgressSec; } String timeString = String.format( "%d:%02d / %d:%02d", currentProgress / 60, currentProgress % 60, duration / 60, duration % 60); if (lastTimeString == null || lastTimeString != null && !lastTimeString.equals(timeString)) { lastTimeString = timeString; int timeWidth = (int) Math.ceil(timePaint.measureText(timeString)); timeLayout = new StaticLayout( timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); } invalidate(); }
@Override public void onSeekBarDrag(float progress) { if (currentMessageObject == null) { return; } currentMessageObject.audioProgress = progress; MediaController.getInstance().seekToProgress(currentMessageObject, progress); }
private void didPressedButton() { if (buttonState == 0) { if (musicDelegate != null) { if (musicDelegate.needPlayMusic(currentMessageObject)) { buttonState = 1; radialProgress.setBackground(getDrawableForCurrentState(), false, false); invalidate(); } } } else if (buttonState == 1) { boolean result = MediaController.getInstance().pauseAudio(currentMessageObject); if (result) { buttonState = 0; radialProgress.setBackground(getDrawableForCurrentState(), false, false); invalidate(); } } else if (buttonState == 2) { radialProgress.setProgress(0, false); FileLoader.getInstance() .loadFile(currentMessageObject.messageOwner.media.document, true, false); buttonState = 3; radialProgress.setBackground(getDrawableForCurrentState(), true, false); invalidate(); } else if (buttonState == 3) { FileLoader.getInstance().cancelLoadFile(currentMessageObject.messageOwner.media.document); buttonState = 2; radialProgress.setBackground(getDrawableForCurrentState(), false, false); invalidate(); } else if (buttonState == 4) { if (currentMessageObject.isOut() && currentMessageObject.isSending()) { if (delegate != null) { delegate.didPressedCancelSendButton(this); } } } }
@Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); MediaController.getInstance().removeLoadingFileObserver(this); }