- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 ReactNative 构建一个媒体播放器。为了完成这样的应用程序,我必须导出一个用于检索音乐元数据(如专辑、艺术家等)以及文件路径的模块。
上面的代码使用 jdk1.8.0_112 可以完美运行,但自从我更新到 jdk1.8.0_144 后,它就停止运行了。
在这个例子中,我没有检查非空、非空、长度> 0等,但我在原来的例子中确实这样做了。
try {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource("Path to the file"); // /storage/337C-1C15/Music/Edguy/Speedhoven.mp3
} catch (RuntimeException ex) {
// java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA
}
我面临两个问题。一方面,我不是一个优秀的 Android 开发者,所以获取一些线索是一项艰巨的任务。另一方面,该错误确实提供了很好的描述。
以防万一你们中的一些人有更好的方法来完成我尝试的事情,我将整个代码留在这里:
@ReactMethod
public void getAll(Callback errorCallback, Callback successCallback){
ContentResolver musicResolver = this.getCurrentActivity().getContentResolver();
Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
if (musicCursor != null && musicCursor.moveToFirst()) {
WritableArray jsonArray = new WritableNativeArray();
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
WritableMap items = new WritableNativeMap();
int titleColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.TITLE);
int idColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media._ID);
int artistColumn = musicCursor.getColumnIndex(android.provider.MediaStore.Audio.Media.ARTIST);
try {
do {
items = new WritableNativeMap();
byte[] art;
long thisId = musicCursor.getLong(idColumn);
String thisPath = musicCursor.getString(musicCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
String thisTitle = musicCursor.getString(titleColumn);
String thisArtist = musicCursor.getString(artistColumn);
String duration = musicCursor.getString(musicCursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
if(thisPath != null && thisPath != "" && thisPath.endsWith(".mp3")) {
mmr.setDataSource(thisPath);
String album = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
String artist = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String title = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
String genre = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_GENRE);
String encoded = "";
String encodedImage = "";
art = mmr.getEmbeddedPicture();
if (album == null) {
album = thisArtist;
}
if (artist == null) {
artist = thisArtist;
}
if (title == null) {
title = thisTitle;
}
if (art != null) {
Bitmap songImage = BitmapFactory.decodeByteArray(art, 0, art.length);
if(songImage != null){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
songImage.compress(Bitmap.CompressFormat.JPEG, 60, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
encodedImage = Base64.encodeToString(byteArray, Base64.DEFAULT);
String pathtoImg = "";
byte[] imageByte = Base64.decode(encodedImage, Base64.DEFAULT);
try {
pathtoImg = Environment.getExternalStorageDirectory() + "/" + thisId + ".jpg";
File filePath = new File(pathtoImg);
FileOutputStream fos = new FileOutputStream(filePath, true);
encoded = pathtoImg;
fos.write(imageByte);
fos.flush();
fos.close();
} catch (FileNotFoundException fnfe) {
errorCallback.invoke(fnfe.getMessage());
} catch (IOException ioe) {
errorCallback.invoke(ioe.getMessage());
}
}
}
String str = String.valueOf(thisId);
items.putString("id", str);
items.putString("album", album);
items.putString("artist", artist);
items.putString("title", title);
items.putString("genre", genre);
if (encoded == "") {
items.putString("cover", "");
} else {
items.putString("cover", "file://" + encoded);
}
items.putString("duration", duration);
items.putString("path", thisPath);
jsonArray.pushMap(items);
}
} while (musicCursor.moveToNext());
successCallback.invoke(jsonArray);
mmr.release();
} catch (RuntimeException e) {
errorCallback.invoke(e.toString());
mmr.release();
} catch (Exception e) {
errorCallback.invoke(e.getMessage());
mmr.release();
}
}
}
当然,我已经看过了:
最佳答案
经过大量调试和研究,我发现了问题。
当文件出现问题时,mmr.setDataSource("path")
似乎会返回 RuntimeException
。 这一点特别重要,因为即使文件存在,也无法检索其元数据。
解决方案是将 MediaMetadataRetriever
使用到 try/catch
中,如下所示:
while(cursor.moveNext()){
try {
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource("Path to the file"); // /storage/337C 1C15/Music/Edguy/Speedhoven.mp3
} catch (RuntimeException ex) {
// something went wrong with the file, ignore it and continue
}
}
关于java - MediaMetadataRetriever.setDataSource( native 方法)导致 RuntimeException : status = 0xFFFFFFEA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46029813/
我尝试使用 Surface View 创建媒体播放器。当我尝试为媒体播放器设置数据源时,出现了 setDataSource 失败异常。如何解决? 代码: @Override public void s
JSTL <sql:setDataSource> 标签用来在 JSP 页面中配置数据源,并将其存储在某作用域的变量中。 语法 JSP <sql:setDataSource>
我已经设法用音频文件填充我的 ListView,但是当单击 ListView 中的项目时没有任何反应,我收到异常“setDataSource failed”。 public class songsFr
我对 MediaMetadataRetriever setdatasource 方法有疑问。我创建了一个简单的项目。 main.xml 只有一个 TextView ,它应该显示 music.mp3 的
我在使用 MediaMetadataRetriever 检索 mp3 文件的艺术家和标题时收到错误(setDataSource 失败 0x8000000),但我不明白为什么。在我的模拟器上运行时,它运
我正在尝试使用 Android MediaMetadataRetriever 获取 mp4 格式的录制视频的长度 - 但出现异常: 07-13 13:54:32.686: E/AndroidRunti
阅读“Media Playback”和“MediaPlayer”android 文档后,我仍然感到困惑,需要有关 setDataSource 的有经验的建议重载方法。 我在项目的 Service 组件
假设我有一个文件的完整路径。将该文件加载到 MediaPlayer 中的更好方法是什么? String filePath = "somepath/somefile.mp3"; mediaPlayer.
我有一个 UIViewController其中包含此属性: @property (weak, nonatomic) IBOutlet UITableView *customerTableView; 在
我是 android 编程的初学者,我想编写 mp3 应用程序以从 URL 调用一些 mp3 文件,所以当我在 android 开发人员中显示“媒体播放器”时,我将 URL 放在 setDataSou
我正在开发一个使用 mediaMetadataRetriever.setDataSource 抓取视频帧的应用程序。但是,当我设置视频路径时,它给了我一个非法参数异常并崩溃。我是 java 和 And
我正在尝试使用 MediaExtract 提取 avi 文件的轨道 0(视频轨道)并使用 MediaCodec 编码为 h264 格式。这是我配置 mediaCodec 的方式 public Medi
我收到以下错误 java.lang.RuntimeException: setDataSource failed: status = 0xFFFFFFEA 我想知道这个状态是什么。我正在使用函数 Me
我正在尝试使用此类获取远程视频的大小,如果视频是远程的,我将收到 IllegalArgumentException。 视频是存储在一台服务器上的mp4... 如果我用 mediaplayer 播放视频
我正在尝试使用 NSarray 使用 NSTableView 创建一个简单的菜单。当我将数据源设置为我创建的类时,出现 EXC_BAD_ACCESS 错误。奇怪的是,它在 macruby 中有效吗?实
我在 VS 2010 sap crystalreports 中遇到问题,使用 c# 制作 Windows 应用程序。 我在使用以下代码时遇到以下错误: CrystalReport1 cr1 = ne
这段代码曾经有效。然后,也许我在某个地方改变了一些东西(或者如果我对 Android 的了解是正确的,则更新在媒体播放器中引入了一个错误)。它停止在 一些 设备上运行!尤其是我的 Nexus S (2
如果使用静态方法MediaPlayer.create(context,id),我可以播放本地mp3,但如果使用非静态方法MediaPlayer.setDataSource(String),则无法正常播
我是 Android 开发新手。我正在尝试根据位置选择歌曲时播放歌曲。它总是崩溃并且有多个错误。我真的不明白我做错了什么。可能是愚蠢的错误,请帮助。 public class BackgroundAu
这个问题很奇怪。问题是,每当我尝试使用时间戳字符串命名文件时,setDataSource 方法都会失败并给出 IOException,但如果我给出诸如包含字母表(例如“Hello.m4a”)的名称,则
我是一名优秀的程序员,十分优秀!