Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Playing a file using MCI

Playing a file using MCI

Scheduled Pinned Locked Moved C#
helpquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Johan Martensson
    wrote on last edited by
    #1

    I have a small form for trying to record but I can't get it to work properly. I have the code below and I can record and play the created file in this application and other media players. The code creates a 8bit 11kHz mono. The problem is when I try to use the "set" parameters, any of them, then I can only play it back in this application, not with any other players. Am I doing something wrong? using Microsoft.VisualBasic.Devices; using Microsoft.VisualBasic; using System.Runtime.InteropServices; using System.Windows.Forms; namespace Recorder { public partial class Form1 : Form { [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)] private static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); public Form1() { InitializeComponent(); } private void buttRecord_Click(object sender, System.EventArgs e) { // record from microphone mciSendString("open new Type waveaudio Alias recsound", "", 0, 0); mciSendString("format tag pcm", "", 0, 0); //mciSendString("set recsound bitspersample 8", "", 0, 0); //mciSendString("set recsound samplespersec 32000", "", 0, 0); mciSendString("set recsound channels 2", "", 0, 0); mciSendString("record recsound", "", 0, 0); } private void buttSaveStop_Click(object sender, System.EventArgs e) { // stop and save mciSendString("save recsound c:\\record.wav", "", 0, 0); mciSendString("close recsound ", "", 0, 0); Computer c = new Computer(); c.Audio.Stop(); } private void buttPlay_Click(object sender, System.EventArgs e) { Computer computer = new Computer(); computer.Audio.Play("c:\\record.wav", AudioPlayMode.Background); } } }

    http://johanmartensson.se - Home of MPEG4Watcher

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups