bonjour,
j'ai trouvé une solution qui permet de faire l'enregistrement audio sous notre chere MVC,
ca marche superbien a 90% .
pourquoi a 90 % ,ben parce que des fois ca marche des fois non,
je sais pas pourquoi,quand je clique sur "save" ca cree le fichier wav,des fois je dois clique deux ou 3 fois pour qu'il cree le fichier ???
si qulqu'un peut m'expliquer ce comportement etrgane,

voici mon code du controleur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.VisualBasic;
using System.Runtime.InteropServices;
using System.IO;
 
namespace audioo.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        [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 ActionResult Index()
        {
 
 
            return View();
        }
 
        public ActionResult rec()
        {
            mciSendString("stop recsound ", "", 0, 0);
            mciSendString("close recsound ", "", 0, 0);
            mciSendString("open new Type waveaudio Alias recsound", "", 0, 0);
            mciSendString("record recsound", "", 0, 0);
 
            Session["recor"] = "enregistrement encours ";
            Session["OK"] = "";
            return RedirectToAction ("index");
        }
 
 
        public ActionResult save()
        {  // stop and save
            //mciSendString("close", "", 0, 0);
 
            //mciSendString("save recsound c://record.wav", "", 0, 0);
            //mciSendString("close recsound ", "", 0, 0);
            //Session["recor"] = "";
            //Session["OK"] = "enregistrement sauvegarder ";
            mciSendString("stop recsound ", "", 0, 0);
            string directoryString = "C://";
            Directory.SetCurrentDirectory(directoryString);
            mciSendString("save recsound record.wav", "", 0, 0);
            mciSendString("close recsound ", "", 0, 0);
            Session["recor"] = "";
            Session["OK"] = "enregistrement sauvegarder ";
            mciSendString("stop", "", 0, 0);
            return RedirectToAction("index");
        }
 
    }
}

voici le code de la page :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
 
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
 
<%:Html.ActionLink("record","rec","home") %>
 
    <h2><%: Session["recor"]%></h2>
 
    <br />
 
    <%:Html.ActionLink("save","save","home") %>
        <h2><%: Session["OK"]%></h2>
 
</asp:Content>


Cdt