use of org.telegram.messenger.audioinfo.AudioInfo in project Telegram-FOSS by Telegram-FOSS-Team.
the class SendMessagesHelper method prepareSendingDocumentInternal.
private static boolean prepareSendingDocumentInternal(AccountInstance accountInstance, String path, String originalPath, Uri uri, String mime, long dialogId, MessageObject replyToMsg, MessageObject replyToTopMsg, CharSequence caption, final ArrayList<TLRPC.MessageEntity> entities, final MessageObject editingMessageObject, long[] groupId, boolean isGroupFinal, boolean forceDocument, boolean notify, int scheduleDate, Integer[] docType) {
if ((path == null || path.length() == 0) && uri == null) {
return false;
}
if (uri != null && AndroidUtilities.isInternalUri(uri)) {
return false;
}
if (path != null && AndroidUtilities.isInternalUri(Uri.fromFile(new File(path)))) {
return false;
}
MimeTypeMap myMime = MimeTypeMap.getSingleton();
TLRPC.TL_documentAttributeAudio attributeAudio = null;
String extension = null;
if (uri != null && path == null) {
boolean hasExt = false;
if (mime != null) {
extension = myMime.getExtensionFromMimeType(mime);
}
if (extension == null) {
extension = "txt";
} else {
hasExt = true;
}
path = MediaController.copyFileToCache(uri, extension);
if (path == null) {
return false;
}
if (!hasExt) {
extension = null;
}
}
final File f = new File(path);
if (!f.exists() || f.length() == 0) {
return false;
}
boolean isEncrypted = DialogObject.isEncryptedDialog(dialogId);
String name = f.getName();
String ext = "";
if (extension != null) {
ext = extension;
} else {
int idx = path.lastIndexOf('.');
if (idx != -1) {
ext = path.substring(idx + 1);
}
}
String extL = ext.toLowerCase();
String permormer = null;
String title = null;
boolean isVoice = false;
int duration = 0;
if (extL.equals("mp3") || extL.equals("m4a")) {
AudioInfo audioInfo = AudioInfo.getAudioInfo(f);
if (audioInfo != null) {
long d = audioInfo.getDuration();
if (d != 0) {
permormer = audioInfo.getArtist();
title = audioInfo.getTitle();
duration = (int) (d / 1000);
}
}
} else if (extL.equals("opus") || extL.equals("ogg") || extL.equals("flac")) {
MediaMetadataRetriever mediaMetadataRetriever = null;
try {
mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(f.getAbsolutePath());
String d = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
if (d != null) {
duration = (int) Math.ceil(Long.parseLong(d) / 1000.0f);
title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
permormer = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
}
if (editingMessageObject == null && extL.equals("ogg") && MediaController.isOpusFile(f.getAbsolutePath()) == 1) {
isVoice = true;
}
} catch (Exception e) {
FileLog.e(e);
} finally {
try {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
if (duration != 0) {
attributeAudio = new TLRPC.TL_documentAttributeAudio();
attributeAudio.duration = duration;
attributeAudio.title = title;
attributeAudio.performer = permormer;
if (attributeAudio.title == null) {
attributeAudio.title = "";
}
attributeAudio.flags |= 1;
if (attributeAudio.performer == null) {
attributeAudio.performer = "";
}
attributeAudio.flags |= 2;
if (isVoice) {
attributeAudio.voice = true;
}
}
boolean sendNew = false;
if (originalPath != null) {
if (originalPath.endsWith("attheme")) {
sendNew = true;
} else if (attributeAudio != null) {
originalPath += "audio" + f.length();
} else {
originalPath += "" + f.length();
}
}
TLRPC.TL_document document = null;
String parentObject = null;
if (!sendNew && !isEncrypted) {
Object[] sentData = accountInstance.getMessagesStorage().getSentFile(originalPath, !isEncrypted ? 1 : 4);
if (sentData != null && sentData[0] instanceof TLRPC.TL_document) {
document = (TLRPC.TL_document) sentData[0];
parentObject = (String) sentData[1];
}
if (document == null && !path.equals(originalPath) && !isEncrypted) {
sentData = accountInstance.getMessagesStorage().getSentFile(path + f.length(), !isEncrypted ? 1 : 4);
if (sentData != null && sentData[0] instanceof TLRPC.TL_document) {
document = (TLRPC.TL_document) sentData[0];
parentObject = (String) sentData[1];
}
}
ensureMediaThumbExists(isEncrypted, document, path, null, 0);
}
if (document == null) {
document = new TLRPC.TL_document();
document.id = 0;
document.date = accountInstance.getConnectionsManager().getCurrentTime();
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
fileName.file_name = name;
document.file_reference = new byte[0];
document.attributes.add(fileName);
document.size = (int) f.length();
document.dc_id = 0;
if (attributeAudio != null) {
document.attributes.add(attributeAudio);
}
if (ext.length() != 0) {
switch(extL) {
case "webp":
document.mime_type = "image/webp";
break;
case "opus":
document.mime_type = "audio/opus";
break;
case "mp3":
document.mime_type = "audio/mpeg";
break;
case "m4a":
document.mime_type = "audio/m4a";
break;
case "ogg":
document.mime_type = "audio/ogg";
break;
case "flac":
document.mime_type = "audio/flac";
break;
default:
String mimeType = myMime.getMimeTypeFromExtension(extL);
if (mimeType != null) {
document.mime_type = mimeType;
} else {
document.mime_type = "application/octet-stream";
}
break;
}
} else {
document.mime_type = "application/octet-stream";
}
if (!forceDocument && document.mime_type.equals("image/gif") && (editingMessageObject == null || editingMessageObject.getGroupIdForUse() == 0)) {
try {
Bitmap bitmap = ImageLoader.loadBitmap(f.getAbsolutePath(), null, 90, 90, true);
if (bitmap != null) {
fileName.file_name = "animation.gif";
document.attributes.add(new TLRPC.TL_documentAttributeAnimated());
TLRPC.PhotoSize thumb = ImageLoader.scaleAndSaveImage(bitmap, 90, 90, 55, isEncrypted);
if (thumb != null) {
document.thumbs.add(thumb);
document.flags |= 1;
}
bitmap.recycle();
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (document.mime_type.equals("image/webp") && editingMessageObject == null) {
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
try {
bmOptions.inJustDecodeBounds = true;
RandomAccessFile file = new RandomAccessFile(path, "r");
ByteBuffer buffer = file.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, path.length());
Utilities.loadWebpImage(null, buffer, buffer.limit(), bmOptions, true);
file.close();
} catch (Exception e) {
FileLog.e(e);
}
if (bmOptions.outWidth != 0 && bmOptions.outHeight != 0 && bmOptions.outWidth <= 800 && bmOptions.outHeight <= 800) {
TLRPC.TL_documentAttributeSticker attributeSticker = new TLRPC.TL_documentAttributeSticker();
attributeSticker.alt = "";
attributeSticker.stickerset = new TLRPC.TL_inputStickerSetEmpty();
document.attributes.add(attributeSticker);
TLRPC.TL_documentAttributeImageSize attributeImageSize = new TLRPC.TL_documentAttributeImageSize();
attributeImageSize.w = bmOptions.outWidth;
attributeImageSize.h = bmOptions.outHeight;
document.attributes.add(attributeImageSize);
}
}
}
final String captionFinal = caption != null ? caption.toString() : "";
final TLRPC.TL_document documentFinal = document;
final String pathFinal = path;
final String parentFinal = parentObject;
final HashMap<String, String> params = new HashMap<>();
if (originalPath != null) {
params.put("originalPath", originalPath);
}
if (forceDocument && attributeAudio == null) {
params.put("forceDocument", "1");
}
if (parentFinal != null) {
params.put("parentObject", parentFinal);
}
Integer prevType = 0;
boolean isSticker = false;
if (docType != null) {
prevType = docType[0];
if (document.mime_type != null && document.mime_type.toLowerCase().startsWith("image/webp")) {
docType[0] = -1;
isSticker = true;
} else if (document.mime_type != null && (document.mime_type.toLowerCase().startsWith("image/") || document.mime_type.toLowerCase().startsWith("video/mp4")) || MessageObject.canPreviewDocument(document)) {
docType[0] = 1;
} else if (attributeAudio != null) {
docType[0] = 2;
} else {
docType[0] = 0;
}
}
if (!isEncrypted && groupId != null) {
if (docType != null && prevType != null && prevType != docType[0]) {
finishGroup(accountInstance, groupId[0], scheduleDate);
groupId[0] = Utilities.random.nextLong();
}
if (!isSticker) {
params.put("groupId", "" + groupId[0]);
if (isGroupFinal) {
params.put("final", "1");
}
}
}
AndroidUtilities.runOnUIThread(() -> {
if (editingMessageObject != null) {
accountInstance.getSendMessagesHelper().editMessage(editingMessageObject, null, null, documentFinal, pathFinal, params, false, parentFinal);
} else {
accountInstance.getSendMessagesHelper().sendMessage(documentFinal, null, pathFinal, dialogId, replyToMsg, replyToTopMsg, captionFinal, entities, null, params, notify, scheduleDate, 0, parentFinal, null);
}
});
return true;
}
use of org.telegram.messenger.audioinfo.AudioInfo in project Telegram-FOSS by Telegram-FOSS-Team.
the class AudioPlayerAlert method updateCover.
private void updateCover(MessageObject messageObject, boolean animated) {
final BackupImageView imageView = animated ? coverContainer.getNextImageView() : coverContainer.getImageView();
final AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
if (audioInfo != null && audioInfo.getCover() != null) {
imageView.setImageBitmap(audioInfo.getCover());
currentFile = null;
currentAudioFinishedLoading = true;
} else {
TLRPC.Document document = messageObject.getDocument();
currentFile = FileLoader.getAttachFileName(document);
currentAudioFinishedLoading = false;
String artworkUrl = messageObject.getArtworkUrl(false);
final ImageLocation thumbImageLocation = getArtworkThumbImageLocation(messageObject);
if (!TextUtils.isEmpty(artworkUrl)) {
imageView.setImage(ImageLocation.getForPath(artworkUrl), null, thumbImageLocation, null, null, 0, 1, messageObject);
} else if (thumbImageLocation != null) {
imageView.setImage(null, null, thumbImageLocation, null, null, 0, 1, messageObject);
} else {
imageView.setImageDrawable(null);
}
imageView.invalidate();
}
if (animated) {
coverContainer.switchImageViews();
}
}
use of org.telegram.messenger.audioinfo.AudioInfo in project Telegram-FOSS by Telegram-FOSS-Team.
the class MusicPlayerService method createNotification.
@SuppressLint("NewApi")
private void createNotification(MessageObject messageObject, boolean forBitmap) {
String songName = messageObject.getMusicTitle();
String authorName = messageObject.getMusicAuthor();
AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class);
intent.setAction("com.tmessages.openplayer");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, 0);
Notification notification;
String artworkUrl = messageObject.getArtworkUrl(true);
String artworkUrlBig = messageObject.getArtworkUrl(false);
long duration = messageObject.getDuration() * 1000;
Bitmap albumArt = audioInfo != null ? audioInfo.getSmallCover() : null;
Bitmap fullAlbumArt = audioInfo != null ? audioInfo.getCover() : null;
loadingFilePath = null;
imageReceiver.setImageBitmap((BitmapDrawable) null);
if (albumArt == null && !TextUtils.isEmpty(artworkUrl)) {
fullAlbumArt = loadArtworkFromUrl(artworkUrlBig, true, !forBitmap);
if (fullAlbumArt == null) {
fullAlbumArt = albumArt = loadArtworkFromUrl(artworkUrl, false, !forBitmap);
} else {
albumArt = loadArtworkFromUrl(artworkUrlBig, false, !forBitmap);
}
} else {
loadingFilePath = FileLoader.getPathToAttach(messageObject.getDocument()).getAbsolutePath();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
boolean isPlaying = !MediaController.getInstance().isMessagePaused();
PendingIntent pendingPrev = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_PREVIOUS).setComponent(new ComponentName(this, MusicPlayerReceiver.class)), PendingIntent.FLAG_CANCEL_CURRENT);
// PendingIntent pendingStop = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_CLOSE).setComponent(new ComponentName(this, MusicPlayerReceiver.class)), PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingStop = PendingIntent.getService(getApplicationContext(), 0, new Intent(this, getClass()).setAction(getPackageName() + ".STOP_PLAYER"), PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingPlaypause = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(isPlaying ? NOTIFY_PAUSE : NOTIFY_PLAY).setComponent(new ComponentName(this, MusicPlayerReceiver.class)), PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingNext = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_NEXT).setComponent(new ComponentName(this, MusicPlayerReceiver.class)), PendingIntent.FLAG_CANCEL_CURRENT);
PendingIntent pendingSeek = PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(NOTIFY_SEEK).setComponent(new ComponentName(this, MusicPlayerReceiver.class)), PendingIntent.FLAG_CANCEL_CURRENT);
Notification.Builder bldr = new Notification.Builder(this);
bldr.setSmallIcon(R.drawable.player).setOngoing(isPlaying).setContentTitle(songName).setContentText(authorName).setSubText(audioInfo != null ? audioInfo.getAlbum() : null).setContentIntent(contentIntent).setDeleteIntent(pendingStop).setShowWhen(false).setCategory(Notification.CATEGORY_TRANSPORT).setPriority(Notification.PRIORITY_MAX).setStyle(new Notification.MediaStyle().setMediaSession(mediaSession.getSessionToken()).setShowActionsInCompactView(0, 1, 2));
if (Build.VERSION.SDK_INT >= 26) {
NotificationsController.checkOtherNotificationsChannel();
bldr.setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL);
}
if (albumArt != null) {
bldr.setLargeIcon(albumArt);
} else {
bldr.setLargeIcon(albumArtPlaceholder);
}
final String nextDescription = LocaleController.getString("Next", R.string.Next);
final String previousDescription = LocaleController.getString("AccDescrPrevious", R.string.AccDescrPrevious);
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
playbackState.setState(PlaybackState.STATE_BUFFERING, 0, 1).setActions(0);
bldr.addAction(new Notification.Action.Builder(R.drawable.ic_action_previous, previousDescription, pendingPrev).build()).addAction(new Notification.Action.Builder(R.drawable.loading_animation2, LocaleController.getString("Loading", R.string.Loading), null).build()).addAction(new Notification.Action.Builder(R.drawable.ic_action_next, nextDescription, pendingNext).build());
} else {
playbackState.setState(isPlaying ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED, MediaController.getInstance().getPlayingMessageObject().audioProgressSec * 1000L, isPlaying ? 1 : 0).setActions(PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY | PlaybackState.ACTION_PAUSE | PlaybackState.ACTION_SEEK_TO | PlaybackState.ACTION_SKIP_TO_PREVIOUS | PlaybackState.ACTION_SKIP_TO_NEXT);
final String playPauseTitle = isPlaying ? LocaleController.getString("AccActionPause", R.string.AccActionPause) : LocaleController.getString("AccActionPlay", R.string.AccActionPlay);
bldr.addAction(new Notification.Action.Builder(R.drawable.ic_action_previous, previousDescription, pendingPrev).build()).addAction(new Notification.Action.Builder(isPlaying ? R.drawable.ic_action_pause : R.drawable.ic_action_play, playPauseTitle, pendingPlaypause).build()).addAction(new Notification.Action.Builder(R.drawable.ic_action_next, nextDescription, pendingNext).build());
}
mediaSession.setPlaybackState(playbackState.build());
MediaMetadata.Builder meta = new MediaMetadata.Builder().putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, fullAlbumArt).putString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST, authorName).putString(MediaMetadata.METADATA_KEY_ARTIST, authorName).putLong(MediaMetadata.METADATA_KEY_DURATION, duration).putString(MediaMetadata.METADATA_KEY_TITLE, songName).putString(MediaMetadata.METADATA_KEY_ALBUM, audioInfo != null ? audioInfo.getAlbum() : null);
mediaSession.setMetadata(meta.build());
bldr.setVisibility(Notification.VISIBILITY_PUBLIC);
notification = bldr.build();
if (isPlaying) {
startForeground(ID_NOTIFICATION, notification);
} else {
stopForeground(false);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify(ID_NOTIFICATION, notification);
}
} else {
RemoteViews simpleContentView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_small_notification);
RemoteViews expandedView = null;
if (supportBigNotifications) {
expandedView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.player_big_notification);
}
notification = new NotificationCompat.Builder(getApplicationContext()).setSmallIcon(R.drawable.player).setContentIntent(contentIntent).setChannelId(NotificationsController.OTHER_NOTIFICATIONS_CHANNEL).setContentTitle(songName).build();
notification.contentView = simpleContentView;
if (supportBigNotifications) {
notification.bigContentView = expandedView;
}
setListeners(simpleContentView);
if (supportBigNotifications) {
setListeners(expandedView);
}
if (albumArt != null) {
notification.contentView.setImageViewBitmap(R.id.player_album_art, albumArt);
if (supportBigNotifications) {
notification.bigContentView.setImageViewBitmap(R.id.player_album_art, albumArt);
}
} else {
notification.contentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_small);
if (supportBigNotifications) {
notification.bigContentView.setImageViewResource(R.id.player_album_art, R.drawable.nocover_big);
}
}
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
notification.contentView.setViewVisibility(R.id.player_next, View.GONE);
notification.contentView.setViewVisibility(R.id.player_previous, View.GONE);
notification.contentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_next, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_previous, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.VISIBLE);
}
} else {
notification.contentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
notification.contentView.setViewVisibility(R.id.player_next, View.VISIBLE);
notification.contentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_next, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_previous, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_progress_bar, View.GONE);
}
if (MediaController.getInstance().isMessagePaused()) {
notification.contentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.contentView.setViewVisibility(R.id.player_play, View.VISIBLE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.GONE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.VISIBLE);
}
} else {
notification.contentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
notification.contentView.setViewVisibility(R.id.player_play, View.GONE);
if (supportBigNotifications) {
notification.bigContentView.setViewVisibility(R.id.player_pause, View.VISIBLE);
notification.bigContentView.setViewVisibility(R.id.player_play, View.GONE);
}
}
}
notification.contentView.setTextViewText(R.id.player_song_name, songName);
notification.contentView.setTextViewText(R.id.player_author_name, authorName);
if (supportBigNotifications) {
notification.bigContentView.setTextViewText(R.id.player_song_name, songName);
notification.bigContentView.setTextViewText(R.id.player_author_name, authorName);
notification.bigContentView.setTextViewText(R.id.player_album_title, audioInfo != null && !TextUtils.isEmpty(audioInfo.getAlbum()) ? audioInfo.getAlbum() : "");
}
notification.flags |= Notification.FLAG_ONGOING_EVENT;
startForeground(ID_NOTIFICATION, notification);
}
if (remoteControlClient != null) {
int currentID = MediaController.getInstance().getPlayingMessageObject().getId();
if (notificationMessageID != currentID) {
notificationMessageID = currentID;
RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(true);
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, authorName);
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, songName);
if (audioInfo != null && !TextUtils.isEmpty(audioInfo.getAlbum())) {
metadataEditor.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, audioInfo.getAlbum());
}
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
if (fullAlbumArt != null) {
try {
metadataEditor.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, fullAlbumArt);
} catch (Throwable e) {
FileLog.e(e);
}
}
metadataEditor.apply();
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
if (remoteControlClient == null || MediaController.getInstance().getPlayingMessageObject() == null) {
return;
}
if (MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration == C.TIME_UNSET) {
AndroidUtilities.runOnUIThread(this, 500);
return;
}
RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(false);
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
metadataEditor.apply();
if (Build.VERSION.SDK_INT >= 18) {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING, Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec * 1000L, 100), MediaController.getInstance().isMessagePaused() ? 0f : 1f);
} else {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
}
}
}, 1000);
}
if (MediaController.getInstance().isDownloadingCurrentMessage()) {
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_BUFFERING);
} else {
RemoteControlClient.MetadataEditor metadataEditor = remoteControlClient.editMetadata(false);
metadataEditor.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, MediaController.getInstance().getPlayingMessageObject().audioPlayerDuration * 1000L);
metadataEditor.apply();
if (Build.VERSION.SDK_INT >= 18) {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING, Math.max(MediaController.getInstance().getPlayingMessageObject().audioProgressSec * 1000L, 100), MediaController.getInstance().isMessagePaused() ? 0f : 1f);
} else {
remoteControlClient.setPlaybackState(MediaController.getInstance().isMessagePaused() ? RemoteControlClient.PLAYSTATE_PAUSED : RemoteControlClient.PLAYSTATE_PLAYING);
}
}
}
}
use of org.telegram.messenger.audioinfo.AudioInfo in project Telegram-FOSS by Telegram-FOSS-Team.
the class MusicBrowserService method handlePlayRequest.
private void handlePlayRequest() {
delayedStopHandler.removeCallbacksAndMessages(null);
if (!serviceStarted) {
try {
startService(new Intent(getApplicationContext(), MusicBrowserService.class));
} catch (Throwable e) {
FileLog.e(e);
}
serviceStarted = true;
}
if (!mediaSession.isActive()) {
mediaSession.setActive(true);
}
MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
if (messageObject == null) {
return;
}
MediaMetadata.Builder builder = new MediaMetadata.Builder();
builder.putLong(MediaMetadata.METADATA_KEY_DURATION, messageObject.getDuration() * 1000);
builder.putString(MediaMetadata.METADATA_KEY_ARTIST, messageObject.getMusicAuthor());
builder.putString(MediaMetadata.METADATA_KEY_TITLE, messageObject.getMusicTitle());
AudioInfo audioInfo = MediaController.getInstance().getAudioInfo();
if (audioInfo != null) {
Bitmap bitmap = audioInfo.getCover();
if (bitmap != null) {
builder.putBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART, bitmap);
}
}
mediaSession.setMetadata(builder.build());
}
Aggregations