读取和播放文件 [英] read and playing file

查看:92
本文介绍了读取和播放文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要逐字节读取声音文件并保存在数组中.然后读取文件2000字节,我要播放数组中的2000字节.怎么办?

I want read a sound file byte by byte and save in array.then read 2000 byte of file, I want play the 2000 byte that is in array.How do it?

推荐答案

为什么?短字节流不太可能包含像真实声音样本之类的东西.

您可以做到:将字节转换为流,然后将其提供给声音播放器.但是我不知道它是否可以用于MP3文件的随机短片段-我怀疑不是.
Why? It is unlikely that a short byte stream will contain anything like a real sound sample.

You can do it: convert the bytes to a stream, and feed that to sound player. But I don''t know if it will work with a random short segment of a MP3 file - I suspect not.
using (Stream s = new MemoryStream(bytes))
   {
   System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(s);
   myPlayer.Play();
   }


这篇关于读取和播放文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆