Only set image duration on images in demo app
The Javadoc is stating that the image duration is ignored for non-image input but this is incorrect (for example, it affects seeking performance). The Javadoc will be updated in another CL. PiperOrigin-RevId: 631730980
This commit is contained in:
parent
38b9a5d441
commit
9adb532b6c
@ -16,8 +16,8 @@
|
|||||||
|
|
||||||
package androidx.media3.transformer;
|
package androidx.media3.transformer;
|
||||||
|
|
||||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
|
import static androidx.media3.transformer.ImageUtil.getCommonImageMimeTypeFromExtension;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -35,7 +35,6 @@ import androidx.media3.datasource.DataSourceBitmapLoader;
|
|||||||
import androidx.media3.datasource.DefaultDataSource;
|
import androidx.media3.datasource.DefaultDataSource;
|
||||||
import androidx.media3.exoplayer.source.MediaSource;
|
import androidx.media3.exoplayer.source.MediaSource;
|
||||||
import androidx.media3.transformer.AssetLoader.CompositionSettings;
|
import androidx.media3.transformer.AssetLoader.CompositionSettings;
|
||||||
import com.google.common.base.Ascii;
|
|
||||||
import com.google.common.util.concurrent.MoreExecutors;
|
import com.google.common.util.concurrent.MoreExecutors;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@ -161,12 +160,7 @@ public final class DefaultAssetLoaderFactory implements AssetLoader.Factory {
|
|||||||
ContentResolver cr = context.getContentResolver();
|
ContentResolver cr = context.getContentResolver();
|
||||||
mimeType = cr.getType(localConfiguration.uri);
|
mimeType = cr.getType(localConfiguration.uri);
|
||||||
} else {
|
} else {
|
||||||
String uriPath = checkNotNull(localConfiguration.uri.getPath());
|
mimeType = getCommonImageMimeTypeFromExtension(localConfiguration.uri);
|
||||||
int fileExtensionStart = uriPath.lastIndexOf(".");
|
|
||||||
if (fileExtensionStart != -1) {
|
|
||||||
String extension = Ascii.toLowerCase(uriPath.substring(fileExtensionStart + 1));
|
|
||||||
mimeType = getCommonImageMimeTypeFromExtension(Ascii.toLowerCase(extension));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mimeType == null) {
|
if (mimeType == null) {
|
||||||
@ -180,46 +174,4 @@ public final class DefaultAssetLoaderFactory implements AssetLoader.Factory {
|
|||||||
"Image format not supported by given bitmapLoader");
|
"Image format not supported by given bitmapLoader");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static String getCommonImageMimeTypeFromExtension(String extension) {
|
|
||||||
switch (extension) {
|
|
||||||
case "bmp":
|
|
||||||
case "dib":
|
|
||||||
return MimeTypes.IMAGE_BMP;
|
|
||||||
case "heif":
|
|
||||||
case "heic":
|
|
||||||
return MimeTypes.IMAGE_HEIF;
|
|
||||||
case "jpg":
|
|
||||||
case "jpeg":
|
|
||||||
case "jpe":
|
|
||||||
case "jif":
|
|
||||||
case "jfif":
|
|
||||||
case "jfi":
|
|
||||||
return MimeTypes.IMAGE_JPEG;
|
|
||||||
case "png":
|
|
||||||
return MimeTypes.IMAGE_PNG;
|
|
||||||
case "webp":
|
|
||||||
return MimeTypes.IMAGE_WEBP;
|
|
||||||
case "gif":
|
|
||||||
return "image/gif";
|
|
||||||
case "tiff":
|
|
||||||
case "tif":
|
|
||||||
return "image/tiff";
|
|
||||||
case "raw":
|
|
||||||
case "arw":
|
|
||||||
case "cr2":
|
|
||||||
case "k25":
|
|
||||||
return "image/raw";
|
|
||||||
case "svg":
|
|
||||||
case "svgz":
|
|
||||||
return "image/svg+xml";
|
|
||||||
case "ico":
|
|
||||||
return "image/x-icon";
|
|
||||||
case "avif":
|
|
||||||
return "image/avif";
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package androidx.media3.transformer;
|
||||||
|
|
||||||
|
import android.net.Uri;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.media3.common.MimeTypes;
|
||||||
|
import androidx.media3.common.util.UnstableApi;
|
||||||
|
import com.google.common.base.Ascii;
|
||||||
|
|
||||||
|
/** Utility methods for images. */
|
||||||
|
@UnstableApi
|
||||||
|
public final class ImageUtil {
|
||||||
|
|
||||||
|
private ImageUtil() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@linkplain MimeTypes MIME type} corresponding to an image {@linkplain Uri URI}
|
||||||
|
* path extension. {@code null} is returned if the extension is not an image extension.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public static String getCommonImageMimeTypeFromExtension(Uri uri) {
|
||||||
|
@Nullable String path = uri.getPath();
|
||||||
|
if (path == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int extensionIndex = path.lastIndexOf('.');
|
||||||
|
if (extensionIndex == -1 || extensionIndex == path.length() - 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String extension = Ascii.toLowerCase(path.substring(extensionIndex + 1));
|
||||||
|
switch (extension) {
|
||||||
|
case "bmp":
|
||||||
|
case "dib":
|
||||||
|
return MimeTypes.IMAGE_BMP;
|
||||||
|
case "heif":
|
||||||
|
case "heic":
|
||||||
|
return MimeTypes.IMAGE_HEIF;
|
||||||
|
case "jpg":
|
||||||
|
case "jpeg":
|
||||||
|
case "jpe":
|
||||||
|
case "jif":
|
||||||
|
case "jfif":
|
||||||
|
case "jfi":
|
||||||
|
return MimeTypes.IMAGE_JPEG;
|
||||||
|
case "png":
|
||||||
|
return MimeTypes.IMAGE_PNG;
|
||||||
|
case "webp":
|
||||||
|
return MimeTypes.IMAGE_WEBP;
|
||||||
|
case "gif":
|
||||||
|
return "image/gif";
|
||||||
|
case "tiff":
|
||||||
|
case "tif":
|
||||||
|
return "image/tiff";
|
||||||
|
case "raw":
|
||||||
|
case "arw":
|
||||||
|
case "cr2":
|
||||||
|
case "k25":
|
||||||
|
return "image/raw";
|
||||||
|
case "svg":
|
||||||
|
case "svgz":
|
||||||
|
return "image/svg+xml";
|
||||||
|
case "ico":
|
||||||
|
return "image/x-icon";
|
||||||
|
case "avif":
|
||||||
|
return "image/avif";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user