androidx / androidx/media

androidx.media3.datasource.FileDataSource$FileDataSourceException While Playing Downloaded Offline Video from File

Open
#1,801 9 comments 0 reactions 1 assignee View on GitHub

@marcbaechinger is already working on this.

Since Oct 14, 2024.

bad media
Dominant language
Java
Stars
3k
Forks
955
Avg merge
12d 14h
Merged PRs (30d)
2

Description

Version

Media3 1.3.1

More version details

Media3 1.3.1

Devices that reproduce the issue

Device:-
Samasung Galaxy F62 Android OS 13.

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Yes

Reproduction steps

Download The Stream shared on This email:- android-media-github@google.com and Save it in In-App Data Scope File Storage Folder , Then retrieve the downlaoded file URI path and play in Media3 and then we are facing the error.

The Downloaded file uri I am passing in Media 3 MediaItem.Builder :- "file:///data/user/0/core2.maz.com.core1/files/.Videos/293711.mp4" through code:
builder = offlineFile.getMediaItem().buildUpon();
Code used to generate "offlineFile" in case of "AppConstants.isTvodApp()":

private MediaSource getOfflineFile(Context context, String simulatedUrl, Menu menu) {
       // Default parameters, except allowCrossProtocolRedirects is true
       DefaultHttpDataSource.Factory httpDataSourceFactory = new DefaultHttpDataSource.Factory()
               .setUserAgent(Util.getUserAgent(this, getString(R.string.kAppName)))
               .setConnectTimeoutMs(DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS)
               .setReadTimeoutMs(DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS)
               .setAllowCrossProtocolRedirects(true);
       DefaultDataSource.Factory dataSourceFactory = new DefaultDataSource.Factory(
               context, httpDataSourceFactory);
       DataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory().setCache(getCache(context)).setCacheReadDataSourceFactory(dataSourceFactory);

       String extension = simulatedUrl.substring(simulatedUrl.lastIndexOf(".") + 1);
       if (!AppUtils.isEmpty(extension) && extension.contains("?")) {
           String[] arr = extension.split("\\?");
           extension = arr[0];
       }
       String fileNameID = GenericUtilsKt.getDownloadedID(menu);
       extension = AppConstants.isTvodApp() ? AppConstants.GEN2_DOWNLOADED_VIDEO_EXTENSION : extension;
       File file = FileManager.getFileOnExternalDirectory(AppConstants.DIRECTORY_NAME_CACHE_VIDEOS + File.separator + fileNameID + "." + extension);
       if(null != file) {
           if (AppConstants.isTvodApp()){
               if (AppFeedManager.downloadStateMap != null &&
                       AppFeedManager.downloadStateMap.containsKey(fileNameID) &&
                       AppFeedManager.downloadStateMap.get(fileNameID) == AppConstants.DOWNLOAD_VIDEO_STATE_TVOD.COMPLETE_STATE){
                   return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
                           .createMediaSource(MediaItem.fromUri(Uri.fromFile(file)));
               }else {
                   return null;
               }
           }else {
               return new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
                       .createMediaSource(MediaItem.fromUri(Uri.fromFile(file)));
           }
       }
       return null;
   }
Expected result

Downloaded Video in File should be loaded and play fine in Media3 Player in Offline Mode.

Actual result

While Playing Offline Downloaded Video File in Media3 Getting error:-
2024-10-11 14:50:36.640 14992-25037 ExoPlayerImplInternal core2.maz.com.core1 E Playback error androidx.media3.exoplayer.ExoPlaybackException: Source error at androidx.media3.exoplayer.ExoPlayerImplInternal.handleIoException(ExoPlayerImplInternal.java:717) at androidx.media3.exoplayer.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:689) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loopOnce(Looper.java:226) at android.os.Looper.loop(Looper.java:313) at android.os.HandlerThread.run(HandlerThread.java:67) Caused by: androidx.media3.datasource.FileDataSource$FileDataSourceException at androidx.media3.datasource.FileDataSource.open(FileDataSource.java:125) at androidx.media3.datasource.DefaultDataSource.open(DefaultDataSource.java:275) at androidx.media3.datasource.cache.CacheDataSource.openNextSource(CacheDataSource.java:799) at androidx.media3.datasource.cache.CacheDataSource.open(CacheDataSource.java:612) at androidx.media3.datasource.StatsDataSource.open(StatsDataSource.java:86) at androidx.media3.exoplayer.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1029) at androidx.media3.exoplayer.upstream.Loader$LoadTask.run(Loader.java:421) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644) at java.lang.Thread.run(Thread.java:1012)

Media

Stream will be shared on :- android-media-github@google.com , Download the stream and Save it to In-App Data Scope File Storage and load it in Media3 via a File URI.

Bug Report
  • You will email the zip file produced by adb bugreport to android-media-github@google.com after filing this issue.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.