C# WinCE下播放*.wav,*.mp3 详解(适用WinCE6.0和以前的所有版本)

电脑杂谈  发布时间:2019-05-12 19:24:54  来源:网络整理

gvtube播放不了_gvtube播放问题_wince6.0播放器

2019阿里云全部产品优惠券(新购或升级都可以使用,强烈推荐)

https://free.aliyun.com/ntms/free/experience/getright199.html。[url=https://www.wang1314.com/doc/topic-8069138-1.html]omg (93)[/url] [url=https://www.wang1314.com/doc/topic-8069125-1.html]omg (6)[/url] [url=https://www.wang1314.com/doc/topic-8069111-1.html]欧米茄1 (328)[/url] [url=https://www.wang1314.com/doc/topic-8069083-1.html]欧米茄omg (57)[/url]。[url=https://www.wang1314.com/doc/topic-8079107-1.html]omg (83)[/url] [url=https://www.wang1314.com/doc/topic-8079076-1.html]omg (98)[/url] [url=https://www.wang1314.com/doc/topic-8079025-1.html]欧米茄omg (51)[/url] [url=https://www.wang1314.com/doc/topic-8078942-1.html]欧米茄 (87)[/url]。

众所周知,ps2带有dvd播放功能,因此早先ps2推出时,不少人将ps2作为家电产品购入,若计算看来,“dvd+游戏机”堪称一个完美的组合,但如今漫步街头,几百元一台的dvd机随处可见,而且质量上乘,支持全区解码更是不在话下,但反观之开价1998元的中国版ps2,dvd遥控板不带不说,仅支持六区解码,两相一对比,买中国版ps2来看dvd不仅严重不合算,真正播放起来恐怕也是问题多多,再加上中国版ps2游戏机只能支持简体中文版ps2游戏软件,而目前将推出的简体中文版ps2游戏按照日本索尼官方的计划,每月将会推出三款,数量少得可怜不说,看看上首发阵容的简体中文ps2游戏都是何种水准,那么其后的那些游戏质量更是可想而知,如此的情况之下,中国版ps2还有何魅力所在呢。打110询问网络诈骗如何报警,被告知了一个电话号码,我打过去询问地址时,接到电话的人听上去一副懒洋洋吊儿郎当非常轻蔑的语气说了一个超市附近,由于他发音不准确,说了两次我没听懂,再次询问时就要发火了的口气。根据询问经销商或厂家、网上查询报价等近期市场价格资料,依据电子设备。

现在贡献出来,希望能帮助其他的朋友少走弯路。

gvtube播放问题_wince6.0播放器_gvtube播放不了

我介绍的方法适用WinCE6.0和以前的所有版本。wince6.0播放器

1.首先介绍如何播放*.wav, 这个方式微软提供了标准的播放类,但不适合播放大文件的*.wav, 只适合10MB以内的简单系统提示语音。

如下:

using System;
using System.Runtime.InteropServices;
using System.IO;
namespace Dengfengsoft
{
    public class Sound
    {
        private byte[] m_soundBytes;
        private string m_fileName;
        //

        private enum Flags
        {
            SND_SYNC = 0x0000,  /* play synchronously (default) */
            SND_ASYNC = 0x0001,  /* plaSmartHomey 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);

        /// <summary>
        /// Construct the Sound object to play sound data from the specified file.
        /// </summary>
        public Sound(string fileName)
        {
            m_fileName = fileName;
        }

        /// <summary>
        /// Construct the Sound object to play sound data from the specified stream.
        /// </summary>
        public Sound(Stream stream)
        {
            // read the data from the stream
            m_soundBytes = new byte[stream.Length];
            stream.Read(m_soundBytes, 0, (int)stream.Length);
        }

        /// <summary>
        /// Play the sound
        /// </summary>
        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));
        }

    }

}
调用方法如下:
private void button1_Click(object sender, EventArgs e)
        {
            Sound soundFile = new Sound("\\Program Files\\music.wav");
            soundFile.Play();
        }

wince6.0播放器_gvtube播放问题_gvtube播放不了

2. 播放MP3文件

这个就比较难了,找了很久才找到的方法。wince6.0播放器

国外的前辈几年前给我们做了一个控件:fmodce.dll, 现在不是免费版了,但本文附件是早期的版本,所以...你懂的。

运行在winCE6.0,和以前的版本都没有问题!

gvtube播放不了_gvtube播放问题_wince6.0播放器

MP3的播放类如下:

using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace Dengfengsoft
{
    public class PlayMP3
    {
        public static IntPtr GetStream(string filename) // 获得音频文件的IntPtr 
        { 
                byte[] filenamebytes = System.Text.Encoding.Default.GetBytes(filename + null); 
                GCHandle hfile = GCHandle.Alloc(filenamebytes, GCHandleType.Pinned); 
                if (Environment.Version.Major == 1) return new IntPtr(hfile.AddrOfPinnedObject().ToInt32() + 4); 
                else return hfile.AddrOfPinnedObject(); 
        } 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Init", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern bool Init(int mixrate, int maxsoftwarechannels, int flags); // 初始化 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_GetLength", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern int GetLength(IntPtr fstream); // 获得流媒体的长度 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_GetPosition", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern UInt32 GetPosition(IntPtr fstream); // 获得流媒体当前播放位置 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Open", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern IntPtr Open(IntPtr data, int mode, int offset, int length); // 打开音频文件 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Play", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern int Play(int channel, IntPtr fstream); // 播放音频文件 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_SetPosition", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern bool SetPosition(IntPtr fstream, UInt32 position); // 定位音频文件播放位置 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Stream_Stop", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern bool Stop(IntPtr fstream); // 停止播放 

        [DllImport("fmodce.dll", EntryPoint = "FSOUND_Close", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Winapi)] 
        public static extern void Close(); // 关闭音频文件 

        [DllImport("coredll.dll", SetLastError = true)] 
        public static extern int SetSystemPowerState(string psState, int StateFlags, int Options); 

        const int POWER_FORCE = 0x1000; 
        const int POWER_STATE_ON = 0x10000; 

    }
}

调用方法如下:

〉〉播放MP3

gvtube播放不了_wince6.0播放器_gvtube播放问题

private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                //调用
                string currentSoundTrack = "\\Program Files\\music.mp3";
                PlayMP3.Init(44100, 16, 0); // 初始化为44.1kHz 
                IntPtr soundStream = PlayMP3.GetStream(currentSoundTrack);
                soundHandle = PlayMP3.Open(soundStream, 16 | 32 | 256, 0, 0);
                PlayMP3.Play(0, soundHandle);
            }
            catch
            {
                MessageBox.Show("播放失败。");
            }
        }

〉〉停止播放

1、executescript 执行 js 时应该是一个闭包的环境,所以这里面 var 定义的变量是局部变量,不可能是全局对象,使用此变量的方法都要在这一个 executescript 里面写好全部代码。ok, 所以 全局变量 会变成 全局对象 的属性, 但对于局部变量它发生了什么, 在函数体内他们是怎么声明的, 很简单、它们变成了(variable object)变量对象的属性. 只是在作为function code的时候有所不同, 一个变量对象不是一个全局对象. 但它会调用一个"activation object"(激活对象), 每一次给函数分配上下文的时候activation object将会被创建.。注意:它只析构全局对象和变量,而不析构局部变量,后面我会列出具体事例程序来说明。

〉〉退出MP3播放器

private void button4_Click(object sender, EventArgs e)
        {
            PlayMP3.Close();//一般放在窗体退出的时候
        }

本文两个例子的完整代码下载(vs2008)


本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/bofangqi/article-98187-1.html

    相关阅读
      发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

      热点图片
      拼命载入中...