Removing files outside of library

This commit is contained in:
Görkem Güclü 2023-01-16 12:12:45 +01:00
parent dad74276ef
commit f518cb660c
7 changed files with 14 additions and 1389 deletions

View File

@ -1,194 +0,0 @@
package com.google.android.exoplayer2.demo;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.LruCache;
import android.view.View;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
import com.google.android.exoplayer2.thumbnail.ThumbnailDescription;
import com.google.android.exoplayer2.util.Log;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
public class DefaultThumbnailProvider implements ThumbnailProvider {
private static final String TAG_DEBUG = DefaultThumbnailProvider.class.getSimpleName();
private LruCache<String, Bitmap> bitmapCache;
private View parent;
//dummy bitmap to indicate that a download is already triggered but not finished yet
private final Bitmap dummyBitmap = Bitmap.createBitmap(1,1,Bitmap.Config.ARGB_8888);
@Nullable ExoPlayer exoPlayer;
public DefaultThumbnailProvider(ExoPlayer exoPlayer, View view) {
this.exoPlayer = exoPlayer;
this.parent = view;
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 4;
bitmapCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {
return bitmap.getByteCount() / 1024;
}
};
}
public Bitmap getThumbnail(long position) {
return getThumbnail(position, true);
}
private Bitmap getThumbnail(long position, boolean retrigger) {
if (exoPlayer != null) {
Object manifest = exoPlayer.getCurrentManifest();
ThumbnailDescription thumbnailDescription = null;
if (manifest instanceof DashManifest) {
DashManifest dashManifest = (DashManifest) manifest;
List<ThumbnailDescription> thumbnailDescs = dashManifest.getThumbnailDescriptions(position);
//selected thumbnail description with lowest bitrate
for (ThumbnailDescription desc : thumbnailDescs) {
if (thumbnailDescription == null || thumbnailDescription.getBitrate() > desc.getBitrate()) {
thumbnailDescription = desc;
}
}
if (bitmapNotAvailableOrDownloadNotTriggeredYet(thumbnailDescription.getUri())) {
this.initThumbnailSource(thumbnailDescription);
return null;
}
}
if (retrigger) {
//also download next and prev thumbnails to have a nicer UI user experience
getThumbnail(thumbnailDescription.getStartTimeMs() + thumbnailDescription.getDurationMs(), false);
getThumbnail(thumbnailDescription.getStartTimeMs() - thumbnailDescription.getDurationMs(), false);
}
return getThumbnailInternal(position, thumbnailDescription);
}
return null;
}
private boolean bitmapNotAvailableOrDownloadNotTriggeredYet(Uri uri) {
Bitmap tmp = bitmapCache.get(uri.toString());
if (tmp != null) return false;
return true;
}
private Bitmap getThumbnailInternal(long position, ThumbnailDescription thumbnailDescription) {
if (thumbnailDescription == null) return null;
Bitmap thumbnailSource = bitmapCache.get(thumbnailDescription.getUri().toString());
if (thumbnailSource == null || thumbnailSource.getWidth() == 1) return null;
if (position < thumbnailDescription.getStartTimeMs() || position > thumbnailDescription.getStartTimeMs() + thumbnailDescription.getDurationMs()) return null;
int count = thumbnailDescription.getTileCountHorizontal() * thumbnailDescription.getTileCountVertical();
int durationPerImage = (int)(thumbnailDescription.getDurationMs() / count);
int imageNumberToUseWithinTile = (int)((position - thumbnailDescription.getStartTimeMs()) / durationPerImage);
//handle special case if position == duration
if (imageNumberToUseWithinTile > count-1) imageNumberToUseWithinTile = count-1;
int intRowToUse = (int)(imageNumberToUseWithinTile / thumbnailDescription.getTileCountHorizontal());
int intColToUse = imageNumberToUseWithinTile - intRowToUse * thumbnailDescription.getTileCountHorizontal();
double thumbnailWidth = (double) thumbnailDescription.getImageWidth() / thumbnailDescription.getTileCountHorizontal();
double thumbnailHeight = (double) thumbnailDescription.getImageHeight() / thumbnailDescription.getTileCountVertical();
int cropXLeft = (int)Math.round(intColToUse * thumbnailWidth);
int cropYTop = (int)Math.round(intRowToUse * thumbnailHeight);
if (cropXLeft + thumbnailWidth <= thumbnailSource.getWidth() && cropYTop + thumbnailHeight <= thumbnailSource.getHeight()) {
return Bitmap.createBitmap(thumbnailSource
, cropXLeft, cropYTop, (int) thumbnailWidth, (int) thumbnailHeight);
}
else {
Log.d(TAG_DEBUG, "Image does not have expected (" + thumbnailDescription.getImageWidth() + "x" + thumbnailDescription.getImageHeight() + ") dimensions to crop. Source " + thumbnailDescription.getUri());
return null;
}
}
private synchronized void initThumbnailSource(ThumbnailDescription thumbnailDescription){
String path = thumbnailDescription.getUri().toString();
if (path == null) return;
if (bitmapCache.get(path) != null) return;
bitmapCache.put(path, dummyBitmap);
RetrieveThumbnailImageTask currentTask = new RetrieveThumbnailImageTask();
currentTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, path);
}
class RetrieveThumbnailImageTask extends AsyncTask<String, Integer, Bitmap> {
String downloadedUrl;
RetrieveThumbnailImageTask() {
}
@Override
protected void onCancelled() {
super.onCancelled();
if (downloadedUrl != null) bitmapCache.remove(downloadedUrl);
}
protected Bitmap doInBackground(String... urls) {
downloadedUrl = urls[0];
InputStream in =null;
Bitmap thumbnailToDownload=null;
int responseCode = -1;
try{
URL url = new URL(downloadedUrl);
if (!isCancelled()) {
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setDoInput(true);
httpURLConnection.connect();
responseCode = httpURLConnection.getResponseCode();
if(responseCode == HttpURLConnection.HTTP_OK)
{
if (!isCancelled()) {
in = httpURLConnection.getInputStream();
if (!isCancelled()) {
thumbnailToDownload = BitmapFactory.decodeStream(in);
}
in.close();
}
}
}
}
catch(Exception ex){
bitmapCache.remove(downloadedUrl);
System.out.println(ex);
}
return thumbnailToDownload;
}
protected void onPostExecute(Bitmap downloadedThumbnail) {
if (downloadedThumbnail != null) {
bitmapCache.put(downloadedUrl, downloadedThumbnail);
if (parent != null) parent.invalidate();
}
else {
bitmapCache.remove(downloadedUrl);
}
}
}
}

View File

@ -75,7 +75,6 @@ public class PlayerActivity extends AppCompatActivity
protected LinearLayout debugRootView;
protected TextView debugTextView;
protected @Nullable ExoPlayer player;
DefaultThumbnailTimeBar timeBar;
private boolean isShowingTrackSelectionDialog;
private Button selectTracksButton;
@ -117,9 +116,6 @@ public class PlayerActivity extends AppCompatActivity
playerView.setControllerVisibilityListener(this);
playerView.setErrorMessageProvider(new PlayerErrorMessageProvider());
playerView.requestFocus();
timeBar = playerView.findViewById(R.id.exo_progress);
if (savedInstanceState != null) {
trackSelectionParameters =
TrackSelectionParameters.fromBundle(
@ -285,7 +281,7 @@ public class PlayerActivity extends AppCompatActivity
player.setPlayWhenReady(startAutoPlay);
playerView.setPlayer(player);
configurePlayerWithServerSideAdsLoader();
timeBar.setThumbnailUtils(new DefaultThumbnailProvider(player, timeBar));
debugViewHelper = new DebugTextViewHelper(player, debugTextView);
debugViewHelper.start();
}

View File

@ -1,9 +0,0 @@
package com.google.android.exoplayer2.demo;
import android.graphics.Bitmap;
public interface ThumbnailProvider {
public Bitmap getThumbnail(long position);
}

View File

@ -1,152 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2020 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.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 0dp dimensions are used to prevent this view from influencing the size of
the parent view if it uses "wrap_content". It is expanded to occupy the
entirety of the parent in code, after the parent's size has been
determined. See: https://github.com/google/ExoPlayer/issues/8726.
-->
<View android:id="@id/exo_controls_background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/exo_black_opacity_60"/>
<FrameLayout android:id="@id/exo_bottom_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/exo_styled_bottom_bar_height"
android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top"
android:layout_gravity="bottom"
android:background="@color/exo_bottom_bar_background"
android:layoutDirection="ltr">
<LinearLayout android:id="@id/exo_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding"
android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"
android:layout_gravity="center_vertical|start"
android:layoutDirection="ltr">
<TextView android:id="@id/exo_position"
style="@style/ExoStyledControls.TimeText.Position"/>
<TextView
style="@style/ExoStyledControls.TimeText.Separator"/>
<TextView android:id="@id/exo_duration"
style="@style/ExoStyledControls.TimeText.Duration"/>
</LinearLayout>
<LinearLayout android:id="@id/exo_basic_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:layoutDirection="ltr">
<ImageButton android:id="@id/exo_vr"
style="@style/ExoStyledControls.Button.Bottom.VR"/>
<ImageButton android:id="@id/exo_shuffle"
style="@style/ExoStyledControls.Button.Bottom.Shuffle"/>
<ImageButton android:id="@id/exo_repeat_toggle"
style="@style/ExoStyledControls.Button.Bottom.RepeatToggle"/>
<ImageButton android:id="@id/exo_subtitle"
style="@style/ExoStyledControls.Button.Bottom.CC"/>
<ImageButton android:id="@id/exo_settings"
style="@style/ExoStyledControls.Button.Bottom.Settings"/>
<ImageButton android:id="@id/exo_fullscreen"
style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>
<ImageButton android:id="@id/exo_overflow_show"
style="@style/ExoStyledControls.Button.Bottom.OverflowShow"/>
</LinearLayout>
<HorizontalScrollView android:id="@id/exo_extra_controls_scroll_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:visibility="invisible">
<LinearLayout android:id="@id/exo_extra_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layoutDirection="ltr">
<ImageButton android:id="@id/exo_overflow_hide"
style="@style/ExoStyledControls.Button.Bottom.OverflowHide"/>
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
<com.google.android.exoplayer2.demo.DefaultThumbnailTimeBar android:id="@id/exo_progress"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_gravity="bottom"
style="@style/ExoStyledControls.TimeBar"
android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom"/>
<LinearLayout android:id="@id/exo_minimal_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="@dimen/exo_styled_minimal_controls_margin_bottom"
android:orientation="horizontal"
android:gravity="center_vertical"
android:layoutDirection="ltr">
<ImageButton android:id="@id/exo_minimal_fullscreen"
style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>
</LinearLayout>
<LinearLayout
android:id="@id/exo_center_controls"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:gravity="center"
android:padding="@dimen/exo_styled_controls_padding"
android:clipToPadding="false">
<ImageButton android:id="@id/exo_prev"
style="@style/ExoStyledControls.Button.Center.Previous"/>
<include layout="@layout/exo_styled_player_control_rewind_button" />
<ImageButton android:id="@id/exo_play_pause"
style="@style/ExoStyledControls.Button.Center.PlayPause"/>
<include layout="@layout/exo_styled_player_control_ffwd_button" />
<ImageButton android:id="@id/exo_next"
style="@style/ExoStyledControls.Button.Center.Next"/>
</LinearLayout>
</merge>

View File

@ -1,11 +1,12 @@
package com.google.android.exoplayer2.thumbnail;
import android.net.Uri;
import androidx.annotation.NonNull;
public class ThumbnailDescription {
private final String id;
private final Uri uri;
@NonNull private final String id;
@NonNull private final Uri uri;
private final int bitrate;
private final int tileCountHorizontal;
private final int tileCountVertical;
@ -14,7 +15,7 @@ public class ThumbnailDescription {
private final int imageWidth; // Image width (Pixel)
private final int imageHeight; // Image height (Pixel)
public ThumbnailDescription(String id, Uri uri, int bitrate, int tileCountHorizontal, int tileCountVertical, long startTimeMs, long durationMs, int imageWidth, int imageHeight) {
public ThumbnailDescription(@NonNull String id, @NonNull Uri uri, int bitrate, int tileCountHorizontal, int tileCountVertical, long startTimeMs, long durationMs, int imageWidth, int imageHeight) {
this.id = id;
this.uri = uri;
this.bitrate = bitrate;
@ -26,6 +27,12 @@ public class ThumbnailDescription {
this.imageHeight = imageHeight;
}
@NonNull
public String getId() {
return id;
}
@NonNull
public Uri getUri() {
return uri;
}

View File

@ -182,6 +182,9 @@ public class DashManifest implements FilterableManifest<DashManifest> {
}
String id = representation.format.id;
if (id == null) {
continue;
}
int bitrate = representation.format.bitrate;
int imageWidth = representation.format.width;
int imageHeight = representation.format.height;