英文:
Does MediaPlayer only play mp3 files that have bit rate mode: variable?
问题
我正在构建一个MP3播放器应用程序,但某些MP3文件无法播放。每次都是相同的MP3文件无法播放。没有出现错误,当我点击播放它们时,一切都好像音频即将播放,但然后没有音频输出,就好像歌曲被冻结。
使用MediaInfo工具(从Mac应用商店获取),我比较了两个能够播放的文件和两个无法播放的文件,并截取了结果的屏幕截图(红色表示字段值不同,黑色表示它们相同)。
左侧的两个是可以工作的,右侧的两个是不能工作的。我唯一能看到的区别是导致问题的歌曲具有恒定的比特率模式。这可能是引起问题的原因吗?如果是这样,是否有一种方法可以使用Java找到音频文件的比特率模式?以及如何将其从恒定模式更改为可变模式?
尽管我认为这不是必要的,因为我所有的其他歌曲都可以工作,但我将在下面发布一些代码。
String songPath = "";
Media mediaFile = MediaHandler.strToMedia(songPath);
MediaHandler.newSong(mediaFile);
MediaHandler.playSong();
MediaHandler类:
public class MediaHandler {
private static MediaPlayer player;
private static Media media;
public static MediaPlayer getPlayer() {
return player;
}
public static Media strToMedia(String songPath) {
File song = new File(songPath);
return new Media(song.toURI().toString());
}
public static void newSong(Media mediaFile) {
if (player != null) {
player.stop();
}
MediaHandler.media = mediaFile;
newPlayer();
}
private static void newPlayer() {
player = new MediaPlayer(media);
}
public static void playSong() {
player.play();
}
}
以上是您提供的内容的翻译。
英文:
I'm building an mp3 player app and certain mp3 files won't play. It's the same mp3 files every time that wont play. No errors are thrown and when I click to play them, everything works as if the audio is about to play, but then no audio comes out, it's like the song freezes.
Using the MediaInfo tool (from the mac app store), I compared 2 files that worked and 2 that didn't and took a screenshot of the results. (Red means the field values are different, black means they are the same)
The 2 on the left are the ones that did work and the 2 on the right are the ones that didn't work. The only difference I can see is the songs causing problems have Bit Rate Mode: Constant. Could this be whats causing problems? If so, is there a way to find an audio files Bit Rate Mode using java? and how would you change it from Constant to Variable?
Although I don't think its necessary since all my other songs work, I'll post some code below.
String songPath = "";
Media mediaFile = MediaHandler.strToMedia(songPath);
MediaHandler.newSong(mediaFile);
MediaHandler.playSong();
The MediaHandler Class:
public class MediaHandler {
private static MediaPlayer player;
private static Media media;
public static MediaPlayer getPlayer(){
return player;
}
public static Media strToMedia(String songPath) {
File song = new File(songPath);
return new Media(song.toURI().toString());
}
public static void newSong(Media mediaFile) {
if (player != null){
player.stop();
}
MediaHandler.media = mediaFile;
newPlayer();
}
private static void newPlayer() {
player = new MediaPlayer(media);
}
public static void playSong() {
player.play();
}
}
答案1
得分: 0
有没有办法使用Java找到音频文件的比特率模式?
您可以使用MediaInfo图形界面来发现问题,您还可以使用其命令行界面(从Java调用命令行)或其库(DyLib)界面(从Java调用API)。
从MediaInfo macOS版本获取命令行界面或DyLib界面,然后调用命令行或者获取Java和MediaInfo之间的“粘合剂” + 实现对MediaInfo的Java调用。
英文:
> is there a way to find an audio files Bit Rate Mode using java?
You use MediaInfo graphical interface for spotting the issue, you can also use its command line interface (calling a command line from Java) or its library (DyLib) interface (calling an API from Java).
Get the Command line interface or the DyLib interface from MediaInfo macOS version, then call the command line or get the "glue" between Java and MediaInfo + implement Java calls to MediaInfo.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论