Windows phone 8.1 播放音频文件的一部分
我必须播放一个大文件的音频部分(300MB+) 这是我的代码: 请注意有关流搜索和大小的评论。该文件从零位开始播放Windows phone 8.1 播放音频文件的一部分,windows-phone-8.1,win-universal-app,Windows Phone 8.1,Win Universal App,我必须播放一个大文件的音频部分(300MB+) 这是我的代码: 请注意有关流搜索和大小的评论。该文件从零位开始播放 如何从指针到指针+长度播放声音?我使用二进制读取器解决了我的问题。我读取字节缓冲区中所需的区域,并将其转换为irandomaccesstream 此版本现在正在运行。只是一个想法-也许您可以在加载后设置,并使用计时器(以适当的间隔)启动它,计时器将停止播放。音频部分是不同长度的语音。我无法估计讲话时间来设置计时器。 // Media source is a local file.
如何从指针到指针+长度播放声音?我使用二进制读取器解决了我的问题。我读取字节缓冲区中所需的区域,并将其转换为irandomaccesstream
此版本现在正在运行。只是一个想法-也许您可以在加载后设置,并使用计时器(以适当的间隔)启动它,计时器将停止播放。音频部分是不同长度的语音。我无法估计讲话时间来设置计时器。
// 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();
}
}
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Data/" + fileName));
using (Stream stream = (await file.OpenReadAsync()).AsStreamForRead())
using (BinaryReader reader = new BinaryReader(stream))
{
reader.BaseStream.Position = pointer;
byte[] buffer = reader.ReadBytes((int)length);
IRandomAccessStream nstream = new MemoryStream(buffer).AsRandomAccessStream();
media.SetSource(nstream, "");
media.Play();
}