简体   繁体   English

没有文件扩展名的 MP3 文件如何在 Android 文件应用程序中播放,有什么方法可以在我的 MP3 播放器 Android 应用程序中播放这些文件?

[英]How can MP3 files without a file extension play in the Android files app and is there any way I can play such files in my MP3 player Android app?

I am creating an MP3 Player app.我正在创建一个 MP3 播放器应用程序。 It's mostly working correctly but there is one edge case.它大部分工作正常,但有一个极端情况。

If a user has a file named "Bieber.mp3" but changes the name of the file to "Bieber" without the file extension in the files app (on Android), they will still be able to play the song properly from the files app depending on the device (older devices like Nexus running on marshmallow will do it while newer devices like the pixel on Android 12 will say it's an invalid file type).如果用户有一个名为“Bieber.mp3”的文件,但在文件应用程序(在 Android 上)中将文件名更改为没有文件扩展名的“比伯”,他们仍然可以从文件应用程序正确播放歌曲取决于设备(像在棉花糖上运行的 Nexus 这样的旧设备会这样做,而像 Android 12 上的像素这样的新设备会说它是无效的文件类型)。

However, when the MP3 file is emailed (or uploaded somewhere in the cloud like drive or Dropbox), the file will have an unknown file type when attempting to from there但是,当 MP3 文件通过电子邮件发送(或上传到云端某处,如驱动器或 Dropbox)时,该文件在尝试从那里传输时将具有未知的文件类型

I want to know, how can MP3 files that are renamed to exclude the.mp3 extension still play in the android files app?我想知道,被重命名为排除 .mp3 扩展名的 MP3 文件如何仍然在 android 文件应用程序中播放? Is there any way I can check to see if a file without the.mp3 extension is still an audio/mp3 file in Java for my mp3 player?有什么方法可以检查没有 .mp3 扩展名的文件是否仍然是我的 mp3 播放器 Java 中的音频/mp3 文件?

If mp3 files without the mp3 extension can play in the android files app, surely there should be some way to play/access them in the MP3 player I'm making, right?如果没有 mp3 扩展名的 mp3 文件可以在 android 文件应用程序中播放,那么肯定应该有一些方法可以在我正在制作的 MP3 播放器中播放/访问它们,对吧?

Well, Android has this library/class called MediaPlayer :好吧,Android 有这个名为MediaPlayer的库/类:

https://developer.android.com/guide/topics/media/mediaplayerhttps://developer.android.com/guide/topics/media/mediaplayer

The MediaPlayer is what you use when you play audio, MediaPlayer是您在播放音频时使用的,

the MediaPlayer takes the input(the file) as long as it is still encoded as an audio file.只要输入(文件)仍被编码为音频文件, MediaPlayer就会接受它。

No matter what you do with the file extension, as long as it is still encoded as audio,不管你对文件扩展名做什么,只要它仍然被编码为音频,

it will stay as an audio file.它将保留为音频文件。

That's why~这就是为什么~

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM