示例#1
0
    /// <summary>Opens a MIDI file.</summary>
    /// <remarks>Used interally only.</remarks>
    /// <exceptions cref="MediaException">Thrown when there was an error opening the file.</exceptions>
    /// <exceptions cref="FileNotFoundException">Thrown when the specified file could not be found.</exceptions>
    protected void OpenFile()
    {
        if (!File.Exists(Filename))
        {
            throw new FileNotFoundException();
        }
        MCI_OPEN_PARMS mciOpenParms = new MCI_OPEN_PARMS();

        mciOpenParms.lpstrDeviceType  = "sequencer";
        mciOpenParms.lpstrElementName = Filename;
        if (mciSendCommandOpen(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_ELEMENT, ref mciOpenParms) != 0)
        {
            throw new MediaException("Failed to open the MIDI device.");
        }
        // The device opened successfully; get the device ID.
        DeviceID = mciOpenParms.wDeviceID;
        // Get the length of the MIDI file
        MCI_STATUS_PARMS mciStatusParms = new MCI_STATUS_PARMS();

        mciStatusParms.dwItem = MCI_STATUS_LENGTH;
        if (mciSendCommandStatus(DeviceID, MCI_STATUS, MCI_WAIT | MCI_STATUS_ITEM, ref mciStatusParms) != 0)
        {
            throw new MediaException("Couldn't get the length of the specified MIDI file.");
        }
        m_Length = mciStatusParms.dwReturn;
    }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        private void Open()
        {
            MCI_OPEN_PARMS op = new MCI_OPEN_PARMS();

            op.dwCallback       = IntPtr.Zero;
            op.lpstrDeviceType  = null;
            op.lpstrElementName = this.SoundLocation;
            op.lpstrAlias       = null;
            op.wDeviceID        = 0;
            MCI_OpenFlags flags = 0;

            //if (deviceType != 0)
            //{
            //    flags = MCI_OpenFlags.MCI_OPEN_TYPE | MCI_OpenFlags.MCI_OPEN_TYPE_ID | MCI_OpenFlags.MCI_OPEN_ELEMENT | MCI_OpenFlags.MCI_WAIT;
            //}
            //else
            //{
            flags = MCI_OpenFlags.MCI_OPEN_ELEMENT | MCI_OpenFlags.MCI_WAIT;
            //}
            IntPtr opPointer = Marshal.AllocHGlobal(Marshal.SizeOf(op));

            try
            {
                Marshal.StructureToPtr(op, opPointer, false);
                UInt32 errorCode = mciSendCommand(0, (UInt32)MCI_Command.MCI_OPEN, (UInt32)flags, opPointer);
                CheckError(errorCode);
                MCI_OPEN_PARMS op2 = (MCI_OPEN_PARMS)Marshal.PtrToStructure(opPointer, typeof(MCI_OPEN_PARMS));
                m_DeviceID = op2.wDeviceID;
            }
            finally
            {
                Marshal.FreeHGlobal(opPointer);
            }
            MCI_SET_PARMS sp = new MCI_SET_PARMS();

            sp.dwCallback   = IntPtr.Zero;
            sp.dwTimeFormat = MCI_Format.MCI_FORMAT_MILLISECONDS;
            IntPtr spPointer = Marshal.AllocHGlobal(Marshal.SizeOf(sp));

            try
            {
                Marshal.StructureToPtr(sp, spPointer, false);
                UInt32 errorCode = mciSendCommand(m_DeviceID, (UInt32)MCI_Command.MCI_SET, (UInt32)(MCI_SetFlags.MCI_SET_TIME_FORMAT | MCI_SetFlags.MCI_WAIT), spPointer);
                CheckError(errorCode);
                if (errorCode != 0)
                {
                    Close();
                }
            }
            finally
            {
                Marshal.FreeHGlobal(spPointer);
            }
        }
        public Dictionary<string, int> GetListSongTime(IEnumerable<string> listSong, bool isAdd)
        {
            Dictionary<string, int> dicSongInfo = new Dictionary<string, int>();
            int i = 10000;
            foreach (string fileFullName in listSong)
            {
                int err;
                int paras = 0;
                StringBuilder buf = new StringBuilder(1000);
                MCI_OPEN_PARMS op = new MCI_OPEN_PARMS();

                if (deviceID > 0)
                {
                    //if (!isAdd)
                    //{
                        Close();
                    //}
                }

                if ((int)timer.Tag == 1)
                {
                    timer.Tag = 0;
                    timer.Stop();
                }

                if (fileFullName.ToString() == "" && deviceType != DeviceType.CDAudio && deviceType != DeviceType.VideoDisc
                    && deviceType != DeviceType.WaveAudio && deviceType != DeviceType.Overlay)
                {
                    //throw new ApplicationException("要打开的文件名为空!");
                }

                paras = MCI_WAIT;
                if (deviceType != DeviceType.CDAudio && deviceType != DeviceType.VideoDisc)
                    paras |= MCI_OPEN_ELEMENT;

                if (deviceType != DeviceType.AutoSelect)
                {
                    if (deviceType == DeviceType.OwnerSelect)
                        op.lpstrDeviceType = GetDriverType(fileFullName);
                    else
                        op.lpstrDeviceType = deviceType.ToString();

                    paras = paras | MCI_OPEN_TYPE;
                }

                if (shareAble)
                {
                    if (fileFullName != string.Empty && deviceType != DeviceType.WaveAudio && deviceType != DeviceType.Overlay)
                        paras = paras | MCI_OPEN_SHAREABLE;
                }

                op.dwCallback = 0;
                op.wDeviceID = 0;
                op.lpstrElementName = fileFullName;

                err = mciSendCommandA(0, MCI_OPEN, paras, ref op);
                deviceID = op.wDeviceID;

                dicSongInfo.Add(fileFullName+(i++), Length);
            }

            return dicSongInfo;
        }
        /// <summary>
        /// 打开多媒体文件。
        /// </summary>
        public void Open()
        {
            int err;
            int paras = 0;
            StringBuilder buf = new StringBuilder(1000);

            MCI_OPEN_PARMS op = new MCI_OPEN_PARMS();

            if (deviceID > 0)
                Close();

            if ((int)timer.Tag == 1)
            {
                timer.Tag = 0;
                timer.Stop();
            }

            if (fileName.ToString() == "" && deviceType != DeviceType.CDAudio && deviceType != DeviceType.VideoDisc
                && deviceType != DeviceType.WaveAudio && deviceType != DeviceType.Overlay)
            {
                //throw new ApplicationException("要打开的文件名为空!");
            }

            paras = MCI_WAIT;
            if (deviceType != DeviceType.CDAudio && deviceType != DeviceType.VideoDisc)
                paras |= MCI_OPEN_ELEMENT;

            if (deviceType != DeviceType.AutoSelect)
            {
                if (deviceType == DeviceType.OwnerSelect)
                    op.lpstrDeviceType = GetDriverType(fileName);
                else
                    op.lpstrDeviceType = deviceType.ToString();

                paras = paras | MCI_OPEN_TYPE;
            }

            if (shareAble)
            {
                if (fileName != string.Empty && deviceType != DeviceType.WaveAudio && deviceType != DeviceType.Overlay)
                    paras = paras | MCI_OPEN_SHAREABLE;
            }

            op.dwCallback = 0;
            op.wDeviceID = 0;
            op.lpstrElementName = fileName;

            err = mciSendCommandA(0, MCI_OPEN, paras, ref op);

            if (err != 0)
            {
                deviceID = 0;
                mciGetErrorStringA(err, buf, 1000);
                throw new ApplicationException("打开文件出错," + buf.ToString());
            }
            else
            {
                deviceID = op.wDeviceID;
                try
                {
                    GetDevcaps();

                    //以帧快进有问题,去掉
                    /*
                    if ((devCaps & DevCaps.CanShowVideo) != DevCaps.CanShowVideo)
                    {
                        if (framesStep == 0)
                            framesStep = 3000;
                    }
                     */

                    if (framesStep == 0)
                        framesStep = Length / 200;

                    if (deviceType == DeviceType.CDAudio || deviceType == DeviceType.VideoDisc)
                    {
                        timeFormat = TimeFormat.TMSF; //set timeformat to use tracks
                        MciSet(0, (int)timeFormat, MCI_WAIT | MCI_SET_TIME_FORMAT);
                    }
                    else
                    {
                        if (timeFormat != TimeFormat.Default)
                            MciSet(0, (int)timeFormat, MCI_WAIT | MCI_SET_TIME_FORMAT);
                    }

                    try
                    {
                        size = GetVideoSize();
                        SetVolume(volume);
                        SetAudio(audioSource);
                        SetMute(mute);
                    }
                    catch { }
                }
                catch (Exception ex)
                {
                    //throw new ApplicationException("打开文件出错," + ex.ToString());
                }
            }
        }
示例#5
0
 private static extern int mciSendCommandOpen(int wDeviceID, int uMessage, int dwParam1, ref MCI_OPEN_PARMS dwParam2);
示例#6
0
 public static extern Int32 mciSendCommand(UInt32 wDeviceID,
                                           e_MSI_CONMMAND uMsg, UInt32 fdwCommand, ref MCI_OPEN_PARMS dwParam);
 private static extern int mciSendCommandA(
     Int32 wDeviceID,  //����������豸ID,�� MCI_OPEN �����wDeviceID��������
     UInt32 uMessage,  //MCI ����
     Int32 dwParam,	  //flags �б�����һ�㶼�� DWORD dwParam �е���س�Ա���ʹ��
     ref  MCI_OPEN_PARMS Any);