[英]Video and audio playback not working on iOS
我正在嘗試將視頻和音頻文件附件合並到應用程序中的論壇帖子中,並且在iOS上無法播放。 在Android上運行正常。 代碼看起來像這樣(對於音頻,對於視頻類似):
String localAudiofilePath = FileSystemStorage.getInstance().getAppHomePath() + (String) fileInfo.get("path");
InputStream is = null;
Media m = null;
try{
is = FileSystemStorage.getInstance().openInputStream(localAudiofilePath);
m = MediaManager.createMedia(is, "audio/" + extractFileExtension((String) fileInfo.get("path")));
}catch(Exception ex){
ex.printStackTrace();
}
m.play();
final Media mm = m;
Display.getInstance().scheduleBackgroundTask(new Runnable() {
@Override
public void run() {
while(mm.isPlaying()){
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
}
mm.cleanup();
}
});
我在控制台中沒有看到任何錯誤,並且在調試時看到沒有輸入catch
塊。 但是,當我嘗試播放音頻時,沒有聲音從設備中發出,並且視頻播放器保持空白,在控制台中顯示以下消息:
2018-01-18 04:22:20.213822 MyApplication [24425:2262915] [Playback]❗️Playback失敗,並出現錯誤:Error Domain = AVFoundationErrorDomain Code = -11800“操作無法完成” UserInfo = {NSUnderlyingError = 0x61000024c2d0 {Error Domain = NSOSStatusErrorDomain代碼= -12893“(null)”},NSLocalizedFailureReason =發生未知錯誤(-12893),NSLocalizedDescription =操作無法完成},無法解決(canResolve:是,errorResolver :(空))
我想念什么?
您正在使用錄音啞劇類型播放視頻。 我想Android會忽略它,這很好。 iOS端口看到流數據的音頻格式,並假定這是音頻文件。 您需要指定要播放的視頻的mime文件類型。
問題根本不是所有媒體播放。 即使iOS沒有報告異常,也沒有輸入catch
子句,但該文件實際上並沒有出現在設備上。 我的錯誤假設是:1.我可以在輸入流實例周圍使用try / catch作為檢查文件是否存在的方法(它在Android上有效,但在iOS上不可用),以及2.如果以下情況,操作系統必定會引發異常:該文件不存在(與1.不同,但捆綁在一起)。
我的新工作代碼如下所示:
String localAudiofilePath = FileSystemStorage.getInstance().getAppHomePath() + MyApplication.DIRECTORY_APP_DOWNLOADS + "/" + (String) fileInfo.get("path");
if(!FileSystemStorage.getInstance().exists(localAudiofilePath)){
Cn1FileUtils.downloadRemoteFile("https://medonline.co.il/uploads/" + (String) fileInfo.get("path"), (String) fileInfo.get("path"), true);
}
InputStream is = null;
media = null;
try{
is = FileSystemStorage.getInstance().openInputStream(localAudiofilePath);
media = MediaManager.createMedia(is, "audio/" + Cn1FileUtils.extractFileExtension((String) fileInfo.get("path")));
}catch(Exception ex){
ex.printStackTrace();
ToastBar.showErrorMessage(MyApplication.getInstance().getString("error_loading_file"));
return;
}
media.play();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.