1
我必须播放大文件(300MB +)以外的音频部分。播放音频文件的一部分
这是我的代码:
// Media source is a local file. // datName = "sound.dat" // pointer = position in file // length = length of the part to play try { file = await StorageFile.GetFileFromApplicationUriAsync (new Uri(@"ms-appx:///Data/" + datName)); // Get the media source as a stream. IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); stream.Seek((ulong)pointer); // This is working, position changes from 0 to pointer stream.Size = (ulong)length; // Is not working, Size remains unchanged at total file size media.SetSource(stream, file.ContentType); media.Play(); } catch (Exception ex) { if (ex is FormatException || ex is ArgumentException) { //ShowFileErrorMsg(); } }
请注意,流求和大小的意见。该文件从位置0播放。
如何从指针播放声音到指针+长度?
只是一个想法 - 也许你可以设置[音频的位置(http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.mediaelement.position)在它被加载之后,并且随着定时器(以适当的间隔)开始它,这将停止播放。 – Romasz
音频部分是不同长度的单词。我无法估计发言时间来设定一个计时器。 – thpitsch