Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
  • Loading branch information
tobiasKaminsky committed May 6, 2021
1 parent a1182ba commit 0492601
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.owncloud.android.R;
import com.owncloud.android.databinding.FragmentPreviewMediaBinding;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.files.FileMenuFilter;
import com.owncloud.android.files.StreamMediaFileOperation;
import com.owncloud.android.lib.common.OwnCloudClient;
Expand Down Expand Up @@ -248,21 +249,36 @@ public void onActivityCreated(Bundle savedInstanceState) {
*/
private void extractAndSetCoverArt(OCFile file) {
if (MimeTypeUtil.isAudio(file)) {
try {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(file.getStoragePath());
byte[] data = mmr.getEmbeddedPicture();
if (data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
binding.imagePreview.setImageBitmap(bitmap); //associated cover art in bitmap
} else {
if (file.getStoragePath() == null) {
setThumbnailForAudio(file);
} else {
try {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource(file.getStoragePath());
byte[] data = mmr.getEmbeddedPicture();
if (data != null) {
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
binding.imagePreview.setImageBitmap(bitmap); //associated cover art in bitmap
} else {
setThumbnailForAudio(file);
}
} catch (Throwable t) {
binding.imagePreview.setImageResource(R.drawable.logo);
}
} catch (Throwable t) {
binding.imagePreview.setImageResource(R.drawable.logo);
}
}
}

private void setThumbnailForAudio(OCFile file) {
Bitmap thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(
ThumbnailsCacheManager.PREFIX_THUMBNAIL + file.getRemoteId());

if (thumbnail != null) {
binding.imagePreview.setImageBitmap(thumbnail);
} else {
binding.imagePreview.setImageResource(R.drawable.logo);
}
}

@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
Expand Down Expand Up @@ -298,7 +314,7 @@ public void onStart() {
binding.exoplayerView.setPlayer(exoPlayer);

if (MimeTypeUtil.isAudio(file)) {
// binding.mediaController.setMediaPlayer(mediaPlayerServiceConnection);
binding.mediaController.setMediaPlayer(mediaPlayerServiceConnection);
mediaPlayerServiceConnection.start(user, file, autoplay, savedPlaybackPosition);
binding.emptyView.emptyListView.setVisibility(View.GONE);
binding.progress.setVisibility(View.GONE);
Expand Down Expand Up @@ -586,6 +602,7 @@ public void onPause() {
@Override
public void onResume() {
super.onResume();
autoplay = false;
Log_OC.v(TAG, "onResume");
}

Expand Down Expand Up @@ -706,5 +723,9 @@ public void onDetach() {

exoPlayer.stop();
exoPlayer.release();

if (!mediaPlayerServiceConnection.isPlaying()) {
stopAudio();
}
}
}
7 changes: 7 additions & 0 deletions src/main/res/layout/fragment_preview_media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
android:layout_gravity="center"
app:show_buffering="when_playing" />

<com.owncloud.android.media.MediaControlView
android:id="@+id/media_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="@dimen/standard_margin" />

<FrameLayout
android:id="@+id/progress"
android:layout_width="match_parent"
Expand Down

0 comments on commit 0492601

Please sign in to comment.