4118|6

61

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

用C#在Pocket PC上播放.wav声音文件,可是听不到任何声音? [复制链接]

想在Pocket PC上写一个程序,用C#播放一个.wav文件当作提示音,可是听不到任何的声音。
代码如下所示,这段代码是直接从MSDN拷贝过来的,但在我的Pocket PC上运行过这段代码却放不出声音,在Visual Stadio 2005的pocket PC 2003 SE 模拟器上可以播放。
我的wav文件也是PCM格式的WAV,而且我的pocket PC硬件也没问题。

--------------------------------------------
public class Sound
{
    private byte[] m_soundBytes;
    private string m_fileName;

    private enum Flags {
        SND_SYNC = 0x0000,  /* play synchronously (default) */
        SND_ASYNC = 0x0001,  /* play asynchronously */
        SND_NODEFAULT = 0x0002,  /* silence (!default) if sound not found */
        SND_MEMORY = 0x0004,  /* pszSound points to a memory file */
        SND_LOOP = 0x0008,  /* loop the sound until next sndPlaySound */
        SND_NOSTOP = 0x0010,  /* don't stop any currently playing sound */
        SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
        SND_ALIAS = 0x00010000, /* name is a registry alias */
        SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
        SND_FILENAME = 0x00020000, /* name is file name */
        SND_RESOURCE = 0x00040004  /* name is resource name or atom */
    }

    [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
    private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);

    [DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
    private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);

    ///
    /// Construct the Sound object to play sound data from the specified file.
    ///

    public Sound (string fileName) {
        m_fileName = fileName;
    }

    ///
    /// Construct the Sound object to play sound data from the specified stream.
    ///

    public Sound(Stream stream)    {
        // read the data from the stream
        m_soundBytes = new byte [stream.Length];
        stream.Read(m_soundBytes, 0,(int)stream.Length);
    }

    ///
    /// Play the sound
    ///

    public void Play () {
        // if a file name has been registered, call WCE_PlaySound,
        //  otherwise call WCE_PlaySoundBytes
        if (m_fileName != null)
            WCE_PlaySound(m_fileName, IntPtr.Zero, (int) (Flags.SND_ASYNC ? Flags.SND_FILENAME));
        else
            WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero, (int) (Flags.SND_ASYNC ? Flags.SND_MEMORY));
    }
}

// To return a Stream object associated with an embedded
// resource, you must prepend the namespace to the original
// name of the file in the project.
private void XXX_Click(object sender, System.EventArgs e) {
    Sound sound = new Sound (Assembly.GetExecutingAssembly().GetManifestResourceStream("SoundSample.chimes.wav"));
    sound.Play();
}
--------------------------------------------

最新回复

在指定文件名时,请使用全路径,因为CE没有当前工作目录的概念  详情 回复 发表于 2009-12-19 08:38
点赞 关注

回复
举报

85

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
可怜每人理,自顶一下。。。
有人在Pocket PC 2003上跑过MSDN的这段代码吗?能放出声音吗?
可否分享以下。
 
 

回复

55

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
你的PPC能发声吗?播放的时候系统是否被静音了?
 
 
 

回复

82

帖子

0

TA的资源

一粒金砂(初级)

4
 
PPC是可以发声的,我直接在ppc点击wav文件可以播放。
 
 
 

回复

71

帖子

0

TA的资源

一粒金砂(初级)

5
 
那在你播放你的音频时,ppc是否被静音了?有音量调节按钮,或者系统的设置里面的选项,看看效果。
还有,WCE也是多任务系统,可以试试和你的程序同时运行一个MediaPlayer,播放声音。如果只有你的程序没声音,那肯定是程序问题了。
 
 
 

回复

76

帖子

0

TA的资源

一粒金砂(初级)

6
 
这个太简单了.明显就是写错了.
 
 
 

回复

78

帖子

0

TA的资源

一粒金砂(初级)

7
 
在指定文件名时,请使用全路径,因为CE没有当前工作目录的概念
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/6 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表