Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyPavlenko committed Dec 7, 2020
1 parent 8a2e48f commit cec6e36
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 31 deletions.
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
def abi = project.properties['ABI']
VERSION_CODE = 76
VERSION_NAME = "1.7.2"
VERSION_CODE = 77
VERSION_NAME = "1.7.3"
SDK_MIN_VERSION = 23
SDK_TARGET_VERSION = 29
SDK_COMPILE_VERSION = 29
Expand All @@ -14,7 +14,7 @@ ext {
ANDROIDX_CORE_VERSION = '1.3.2'
ANDROIDX_MEDIA_VERSION = '1.2.0'
ANDROIDX_APPCOMPAT_VERSION = '1.2.0'
ANDROIDX_CONSTRAINTLAYOUT_VERSION = '2.0.4'
ANDROIDX_CONSTRAINTLAYOUT_VERSION = '2.0.1'
}

buildscript {
Expand All @@ -25,7 +25,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.1'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.google.gms:google-services:4.3.4'
}
}
Expand Down Expand Up @@ -65,6 +65,10 @@ subprojects {
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
resConfigs "en", "ru"

ndk {
abiFilters = ABI_FILTERS
}
}

if (isDynFeature) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.graphics.Bitmap;
import android.media.MediaMetadata;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.provider.MediaStore;
import android.support.v4.media.MediaMetadataCompat;

import androidx.annotation.Nullable;
Expand All @@ -31,6 +31,7 @@
import me.aap.utils.text.SharedTextBuilder;
import me.aap.utils.text.TextBuilder;
import me.aap.utils.vfs.VirtualResource;
import me.aap.utils.vfs.content.ContentFileSystem;

import static me.aap.utils.async.Completed.completedEmptyMap;
import static me.aap.utils.async.Completed.completedVoid;
Expand All @@ -53,6 +54,14 @@ public class MetadataRetriever implements Closeable {
private static final String COL_ID_PATTERN = COL_ID + " LIKE ? AND NOT " + COL_ID + " LIKE ?";
private static final String[] QUERY_COLUMNS = {COL_ID, COL_TITLE, COL_ALBUM, COL_ARTIST,
COL_DURATION, COL_ART};
private static final String[] CONTENT_COLUMNS = {
MediaStore.MediaColumns.TITLE,
MediaStore.Audio.AudioColumns.DURATION,
MediaStore.Audio.AudioColumns.ARTIST,
"album_artist",
MediaStore.Audio.AudioColumns.ALBUM,
MediaStore.Audio.AudioColumns.COMPOSER,
"genre"};

private final MediaEngineManager mgr;
private final BitmapCache bitmapCache;
Expand Down Expand Up @@ -102,9 +111,22 @@ private MetadataBuilder load(PlayableItem item) {
if (meta != null) return meta;

MetaBuilder mb = new MetaBuilder();
VirtualResource file = item.getResource();

if (file.getVirtualFileSystem() instanceof ContentFileSystem) {
if (queryContentProvider(file.getRid().toAndroidUri(), mb)) {
try {
insertMetadata(mb, item);
} catch (Throwable ex) {
Log.e(ex, "Failed to update MediaStore");
}

return mb;
}
}

MediaEngineProvider mp = mgr.mediaPlayer;
MediaEngineProvider vlc = mgr.vlcPlayer;
VirtualResource file = item.getResource();

if (file.isLocalFile() && file.getName().endsWith(".flac")) {
// VLC does not extract images from flac, thus prefer Android extractor for local files
Expand All @@ -127,6 +149,40 @@ private MetadataBuilder load(PlayableItem item) {
return mb;
}

private boolean queryContentProvider(Uri uri, MetaBuilder mb) {
try (Cursor c = App.get().getContentResolver().query(uri, CONTENT_COLUMNS, null, null, null)) {
if ((c == null) || !c.moveToFirst()) return false;

String m = c.getString(1);

if ((m != null) && !m.isEmpty()) {
try {
mb.putLong(MediaMetadata.METADATA_KEY_DURATION, Long.parseLong(m));
} catch (NumberFormatException ex) {
Log.d(ex);
return false;
}
} else {
return false;
}

m = c.getString(0);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_TITLE, m);
m = c.getString(2);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, m);
m = c.getString(3);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_ALBUM_ARTIST, m);
m = c.getString(4);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_ALBUM, m);
m = c.getString(5);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_COMPOSER, m);
m = c.getString(6);
if (m != null) mb.putString(MediaMetadataCompat.METADATA_KEY_GENRE, m);

return true;
}
}

public FutureSupplier<Map<String, MetadataBuilder>> queryMetadata(String idPattern) {
return (db != null) ? queue.enqueue(() -> query(idPattern)) : completedEmptyMap();
}
Expand Down Expand Up @@ -239,15 +295,6 @@ private void insertMetadata(MetaBuilder meta, PlayableItem item) {
db.insert(TABLE, null, values);
}

@SuppressWarnings("unused")
private static boolean isBitmapUri(Context ctx, String u, Uri uri) {
try (ParcelFileDescriptor fd = ctx.getContentResolver().openFileDescriptor(uri, "r")) {
return true;
} catch (Exception ex) {
return false;
}
}

private void createTable() {
if (db == null) return;

Expand Down
3 changes: 1 addition & 2 deletions fermata/src/main/java/me/aap/fermata/media/lib/MediaLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import me.aap.utils.holder.IntHolder;
import me.aap.utils.vfs.VirtualFileSystem;
import me.aap.utils.vfs.VirtualResource;
import me.aap.utils.vfs.content.ContentFileSystem;
import me.aap.utils.vfs.generic.GenericFileSystem;

import static android.support.v4.media.MediaMetadataCompat.METADATA_KEY_ALBUM_ART_URI;
Expand Down Expand Up @@ -267,7 +266,7 @@ interface PlayableItem extends Item {

default boolean isStream() {
VirtualFileSystem.Provider p = getResource().getVirtualFileSystem().getProvider();
return (p instanceof GenericFileSystem.Provider) || (p instanceof ContentFileSystem.Provider);
return (p instanceof GenericFileSystem.Provider);
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,13 @@ public boolean isBarsHidden() {
}

public void setBarsHidden(boolean barsHidden) {
this.barsHidden = barsHidden;
int visibility = barsHidden ? GONE : VISIBLE;
ToolBarView tb = getToolBar();
if (tb.getMediator() != ToolBarView.Mediator.Invisible.instance) tb.setVisibility(visibility);
getNavBar().setVisibility(visibility);
App.get().getHandler().post(() -> {
this.barsHidden = barsHidden;
int visibility = barsHidden ? GONE : VISIBLE;
ToolBarView tb = getToolBar();
if (tb.getMediator() != ToolBarView.Mediator.Invisible.instance) tb.setVisibility(visibility);
getNavBar().setVisibility(visibility);
});
}

public void setVideoMode(boolean videoMode, @Nullable VideoView v) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,13 @@ public void reload() {
}

public void refresh() {
getLib().getVfsManager().clearCache();
getAdapter().getParent().refresh();
reload();
}

public void rescan() {
getLib().getVfsManager().clearCache();
getAdapter().getParent().rescan();
reload();
}
Expand Down
4 changes: 0 additions & 4 deletions modules/exoplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ android {
defaultConfig {
versionCode 1
versionName "1.0"

ndk {
abiFilters = ABI_FILTERS
}
}
}

Expand Down
4 changes: 0 additions & 4 deletions modules/vlc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ android {
defaultConfig {
versionCode 1
versionName "1.0"

ndk {
abiFilters = ABI_FILTERS
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
webView.loadUrl(url);
}

@Override
public void onPause() {
MainActivityDelegate a = MainActivityDelegate.get(getContext());

if ((a != null) && !a.isCarActivity()) {
FermataServiceUiBinder b = a.getMediaServiceBinder();
if ((b != null) && (YoutubeMediaEngine.isYoutubeItem(b.getCurrentItem()))) {
b.getMediaSessionCallback().onStop();
}
}

super.onPause();
}

public void loadUrl(String url) {
FermataWebView v = getWebView();
if (v != null) v.loadUrl(url);
Expand Down

0 comments on commit cec6e36

Please sign in to comment.