我正在尝试使用 CrossMediaManager 播放媒体项目列表。但是,在 IOS 中,它会抛出一个奇怪的错误并且不执行播放,而相同的代码在 Android 中可以工作。如果我确实传递了单个字符串 url 或媒体项目,那么它可以工作,但它不适用于多个 url。
static async Task<MediaItem> GenerateReciterMediaItem(string fileUri, AudioReciter reciter, byte chapterId)
{
Chapter c = await Chapter.GetChapterAsync(chapterId);
var item = (MediaItem)await CrossMediaManager.Current.Extractor.CreateMediaItem(fileUri);
item.MediaType = MediaType.Audio;
var reciterImageUri = Path.Combine("http://www.azee.tech/reciters/r9.png"); //doesn't work
//another url for image reciter.azee.tech/r9.png --> also doesn't work
var image = new Image() { Source = ImageSource.FromUri(new Uri(reciterImageUri))};
int type = 1;
if (item != null)
{
item.Id = string.Format("{0},{1},{2}", type, chapterId, reciter.ReciterID);
item.IsMetadataExtracted = false;
item.Title = reciter.Name;
item.Album = string.Format("{0} - {1} ({2})", c.ChapterID, c.ArabicEnglishName, c.EnglishName);
item.Artist = reciter.Name;
item.AlbumImage = image;
item.AlbumImageUri = reciterImageUri;
item.DisplayImage = image;
item.DisplayImageUri = reciterImageUri;
item.Image = image;
item.ImageUri = reciterImageUri;
}
return item;
}
static async Task AddAudioReciterTrackToQueue()
{
//list of urls --> https://www.azee.tech/MaherAlMuaiqly64kbps/001.mp3 , 002.mp3, 003.mp3 and so on
foreach(var url in listOfUrls)
{
var fileUri = listOfUrls[i];
var item = await GenerateReciterMediaItem(fileUri, type, reciter, chapterId);
CrossMediaManager.Current.Queue.Add(item);
}
}
async Task PlayQueue()
{
CrossMediaManager.Current.AutoPlay = true;
await AddAudioReciterTrackToQueue();
await CrossMediaManager.Current.Play(CrossMediaManager.Current.Queue.MediaItems); //doesnt work
await CrossMediaManager.Current.Play(); //doesn't work
}
调试错误
2020-09-15 22:31:43.550896+0100 wQuran.iOS[29476:23403374] -[AVAsset loadValuesAsynchronouslyForKeys:completionHandler:] 使用无法识别的键(专辑名称、作者、标题、艺术家)调用。[0:] state changed Buffering Thread started: #22 2020-09-15 22:31:43.758802+0100 wQuran.iOS[29476:23404151] -[AVAsset loadValuesAsynchronouslyForKeys:completionHandler:] 使用无法识别的键(艺术品)调用。
如果我下载文件并从本地资源播放它。没有错误。我还在 info.plist 中添加了传输安全性以忽略来自该域的 https
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>www.azee.tech</key>
<dict>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>