Ошибка воспроизведения звука в консольном приложении - C#

Узнай цену своей работы

Формулировка задачи:

Почему не хочет воспроизводится звук(в консольном приложении)??? Этот же код в формах все нормально воспроизводит!!! Пробовал и с потоками писать и все равно не хочет!! Подскажите плиз!!!!
using System.Threading;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
 
namespace _231
{
    class Program
    {
        [DllImport("winmm.dll")]
        private static extern long mciSendString(string Cmd, StringBuilder StrReturn, int ReturnLength, IntPtr HwndCallback);
 
        static void Main(string[] args)
        {
            string FileName = @"E:\mus\003-yolanda_be_cool_and_dcup_-_we_no_speak_americano.mp3";
 
            mciSendString("open \"" + FileName + "\" type mpegvideo alias MediaFile", null, 0, IntPtr.Zero);
            mciSendString("seek MediaFile to " + 10 * 1000, null, 0, IntPtr.Zero);
            mciSendString("play MediaFile", null, 0, IntPtr.Zero);
            mciSendString("setaudio MediaFile volume to " + 100 * 10, null, 0, IntPtr.Zero);
            Console.ReadKey();
        }
    }
}

Решение задачи: «Ошибка воспроизведения звука в консольном приложении»

textual
Листинг программы
using System;
using System.Text;
using System.Runtime.InteropServices;
 
namespace media
{
    class Program
    {
        [DllImport("winmm.dll")]
        static extern Int32 mciSendString(string Cmd, StringBuilder StrReturn, int ReturnLength, IntPtr HwndCallback);
 
        [DllImport("winmm.dll")]
        static extern Int32 mciGetErrorString(Int32 errorCode, StringBuilder errorText, Int32 errorTextSize);
 
        static void Main(string[] args)
        {
            StringBuilder buffer = new StringBuilder(128);
            string fileName = @"E:\athlete-wires.mp3";
 
            string sCommand = "open \"" + fileName + "\" type mpegvideo alias MediaFile";
            Int32 errCode = mciSendString(sCommand, null, 0, IntPtr.Zero);
            mciGetErrorString(errCode, buffer, buffer.Capacity);
            Console.WriteLine("Error text: {0}", buffer.ToString());
            
            sCommand = "play " + fileName + " from 0";
            errCode = mciSendString(sCommand, null, 0, IntPtr.Zero);
            mciGetErrorString(errCode, buffer, buffer.Capacity);
            Console.WriteLine("Error text: {0}", buffer.ToString());
            Console.ReadKey();
        }
    }
}

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

11   голосов , оценка 3.727 из 5
Похожие ответы