I have solved the problem.
The media file i tested is not an real .wav file even with an extension of wav. When playing the file, player may turn the file to correct wav file, then i can get the info of file.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to get duration of an url audio.
NSUrl nsurl = NSUrl.FromFilename(url);
AVUrlAssetOptions option = new AVUrlAssetOptions();
option.PreferPreciseDurationAndTiming = true;
avassetTem = new AVUrlAsset(url, option);
string duration = avassetTem.Duration.Seconds.ToString();
Var url is a '.wav' file saved on server. I want to load duration of it. But with these code i can only get '0'.
Trying so many ways, i can get duration only when i play the audio with AVPlayer instance and then get duration from CurrentItem.Duration after audio played over.
AudioSession.Category = AudioSessionCategory.MediaPlayback;
player = new AVPlayer(NSUrl.FromFilename(path));
player.ActionAtItemEnd = AVPlayerActionAtItemEnd.Pause;
player.Play();
await Task.Delay(1000);
var duration = player.CurrentItem.Duration.Seconds;
I'm using ios simulator.
I have solved the problem.
The media file i tested is not an real .wav file even with an extension of wav. When playing the file, player may turn the file to correct wav file, then i can get the info of file.
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more