Ich konnte kein Video im Pfad abspielen (/Speicher/emuliert/0/Android/data/com ...)
Posted: 10 Feb 2025, 09:05
Ich habe mein Video intern mit dem folgenden Code auf dem Telefon gespeichert: < /p>
Gibt es eine andere Möglichkeit, ein Video im Android MediaPlayer zu spielen ? P> Tatsächlich hat ich herausgefunden, dass ich auf den Ordner des Vermögens hingewiesen habe, da ich diesen Blog -Beitrag verfolgte. gist.github.com/huxaiphhaer/268b94a0e7959822fa679a7523701187
Code: Select all
public static void DownloadVideo(Context context, String URL) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(URL));
Date date = new Date();
SimpleDateFormat videoName = new SimpleDateFormat("yyyymmdd_HHmmss");
String strDate = videoName.format(date);
request.setDescription("Setting up the AR");
request.setTitle("AR setup ...");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
}
request.setDestinationInExternalFilesDir(context, "/NewVisionARVideos/", "" + strDate + System.currentTimeMillis() + ".mp4");
System.out.println("count files --- " + context.getExternalFilesDir(null).listFiles());
for(int i = 0; i < context.getExternalFilesDir(null).listFiles().length; i++){
System.out.println("** each file -- " + context.getExternalFilesDir(null).listFiles()[i]);
}
DownloadManager manager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
}
< /code>
Dies i Was ich in der Manifestdatei hinzugefügt habe: < /p>
< /code>
Dies ist der Pfad, der zum Laden des Videos zeigt: < /p>
String path = "/storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4";
< /code>
Unten ist der Fehler, den ich bekomme, wenn ich versuche, das Video im Media Player abzuspielen. Der Pfad ist korrekt und ich habe die Berechtigungen im Manifest und auch im Telefon aktiviert.D/ArVideoFragment: playbackVideo = /storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4
E/ArVideoFragment: Could not play video [/storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4]
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.shliama.augmentedvideotutorial/files/NewVisionARVideos/test.mp4