Hello
I'm a beginner in csharp,when I try to run a code in visual csharp 2010 I get this message "L'assembly en mode mixte est créé avec la version 'v1.1.4322' du runtime et ne peut pas être chargé dans le runtime 4.0 sans d'autres informations de configuration".
I'm using windows 7,my frame work is .net 4.0
can you give me a solution please?
And thank you :)
Loading
nicole castelPosted Apr 25, 2011, 9:24 AM
VulpesPosted Apr 25, 2011, 9:06 AM
string chemin = "..//..//Sequences//alarme.wav";
then the folder always needs to be two levels higher in the directory tree than your .exe.
nicole castelPosted Apr 25, 2011, 8:30 AM
CrishPosted Apr 25, 2011, 8:19 AM
http://www.axistechnolabs.com/technology/ecommerce-development.aspx]ecommerce development company[/url]
nicole castelPosted Apr 25, 2011, 7:14 AM
now i can read my sound file in any pc but I didn't use System.Resource.ResourceReader
This is my code:
System.Media.SoundPlayer sp = new SoundPlayer();
private void button1_Click(object sender, EventArgs e)
{
//Dans ton constructeur :
string chemin = "..//..//Sequences//alarme.wav";
sp.SoundLocation = chemin;
sp.LoadCompleted += new AsyncCompletedEventHandler(sp_LoadCompleted);
sp.LoadAsync();
}
//Puis
private void sp_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
sp.PlayLooping();
}
I created a new folder: "Add" -> "New Folder" -> my folder name is Sequenes ->than I clicked on Sequences -> "Add" -> "Existing Item"-> I added alarme.wav
Did you think that it's a good idea?
nicole castelPosted Apr 23, 2011, 3:41 AM
Sam HobbsPosted Apr 22, 2011, 8:39 PM
She needs to be able to select a microphone from multiple microphones and also select a speaker from multiple speakers and then stream the output of the selected microphone to the selected speakers. Her requirements might have changed but if they are the same as before then that is what she needs to do. Can System.Media.SoundPlayer do that?
I hope Nicole can confirm whether her current requirements are as they were in the past or if they have changed.
VulpesPosted Apr 22, 2011, 11:52 AM
I was thinking before that, even if you did that, you'd still need to stream the files to disk so that you could set the SoundLocation property to the appropriate file path.
However, I've been looking at the documentation for the SoundPlayer class and there's a Stream property which may allow you to set it directly to the resource stream without having to save to disk first.
nicole castelPosted Apr 22, 2011, 11:40 AM
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Reflection;
namespace MyNamespace
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support.
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call.
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(4, 8);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(284, 192);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(92, 236);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(192, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 208);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "Show Image";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 236);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "Get Text";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.AddRange(new System.Windows.Forms.Control[]{
this.button2,
this.button1,
this.textBox1,
this.pictureBox1});
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
Assembly _assembly;
Stream _imageStream;
StreamReader _textStreamReader;
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
_assembly = Assembly.GetExecutingAssembly();
_imageStream = _assembly.GetManifestResourceStream("MyNamespace.MyImage.bmp");
_textStreamReader = new StreamReader(_assembly.GetManifestResourceStream("MyNamespace.MyTextFile.txt"));
}
catch
{
MessageBox.Show("Error accessing resources!");
}
}
private void button1_Click(object sender, System.EventArgs e)
{
try
{
pictureBox1.Image = new Bitmap(_imageStream);
}
catch
{
MessageBox.Show("Error creating image!");
}
}
private void button2_Click(object sender, System.EventArgs e)
{
try
{
if(_textStreamReader.Peek() != -1)
{
textBox1.Text = _textStreamReader.ReadLine();
}
}
catch
{
MessageBox.Show("Error writing text!");
}
}
}
}
VulpesPosted Apr 22, 2011, 11:40 AM
string filePath = Application.StartupPath + "\\wavfiles\\" + whatever.wav;
VulpesPosted Apr 22, 2011, 11:11 AM
Failing that you're going to need to install the sound files (say, in a sub-folder of the .exe's folder) when you install your application on the user's machine. Otherwise they could be anywhere, if indeed they're installed at all!
nicole castelPosted Apr 22, 2011, 11:01 AM
VulpesPosted Apr 22, 2011, 10:46 AM
nicole castelPosted Apr 22, 2011, 10:31 AM
In my application the user shouldn't chose a sound file,it should be related to the button.I mean when I select the button I can hear the specific sound.
VulpesPosted Apr 22, 2011, 10:20 AM
nicole castelPosted Apr 22, 2011, 9:36 AM
Now I can read a sound file, I found this code in the net and I tried to correct it using your advices:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Runtime.InteropServices;
using System.Media;
namespace alarmee
{
public partial class Form1 : Form
{
public Audio Lecteur;
public bool lecture = false;
public Form1()
{
InitializeComponent();
}
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true, CharSet = CharSet.Unicode, ThrowOnUnmappableChar = true)]
private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
private void button4_Click(object sender, EventArgs e)
{
}
System.Media.SoundPlayer sp = new SoundPlayer();
private void button1_Click(object sender, EventArgs e)
{
//Dans ton constructeur :
sp.SoundLocation = "C:\\Sample\\alarme.wav";
sp.LoadCompleted += new AsyncCompletedEventHandler(sp_LoadCompleted);
sp.LoadAsync();
}
//Puis
private void sp_LoadCompleted(object sender, AsyncCompletedEventArgs e)
{
sp.PlayLooping();
}}}
Now I want to read the sound file witout precising its location because it's not practical to demand to a person who want to use my application to have the same file.wasv in the same location.
Hope you can understand what I wrote.
Thank you in advance
Good day
nicole castelPosted Apr 5, 2011, 8:46 AM
FroglegPosted Apr 5, 2011, 8:16 AM
using System.Media;
private void button1_Click(object sender, EventArgs e)
{
SoundPlayer simpleSound = new SoundPlayer(audio file to play eg "sample.wav");
simpleSound.Play();
}
nicole castelPosted Apr 5, 2011, 7:59 AM
FroglegPosted Apr 5, 2011, 7:56 AM
using Microsoft.DirectX.AudioVideoPlayback;
It runs in c# 2008 but not C#2010
nicole castelPosted Apr 5, 2011, 6:24 AM
but I still having the same problem,Sorry if i'm bothering you but I really need your help
Vijay YadavPosted Apr 5, 2011, 6:14 AM
Krishna GaradPosted Apr 5, 2011, 6:12 AM
nicole castelPosted Apr 5, 2011, 6:09 AM
Vijay YadavPosted Apr 5, 2011, 5:53 AM
Go to solution explorer, right-click on it and say add new item and select app.config from the list.
nicole castelPosted Apr 5, 2011, 5:39 AM
where I can find it???????
Mamta MPosted Apr 5, 2011, 5:27 AM
-Mamta
nicole castelPosted Apr 5, 2011, 5:25 AM
nicole castelPosted Apr 5, 2011, 5:14 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace lecteur_audio
{
///
/// Logique d'interaction pour MainWindow.xaml
///
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public Audio Lecteur;
public bool lecture = false;
public bool pause = false;
public string chemin = null;
private void Btn_Lecture_Click(object sender, RoutedEventArgs e)
{
try
{
if (chemin != null )
{
if (lecture != true)
{
if (pause == false)
{
Lecteur = new Audio (chemin);
}
Lecteur.Play();
lecture = true;
pause = false;
}
}
}
catch (Exception ex)
{
}
}
private void Btn_Pause_Click(object sender, RoutedEventArgs e)
{
try
{
if (lecture == true)
Lecteur.Pause();
lecture = false;
pause = true;
}
catch (Exception ex)
{
}
}
private void Btn_Arret_Click(object sender, RoutedEventArgs e)
{
try
{
if (lecture == true)
Lecteur.Stop();
lecture = false;
pause = false;
}
catch (Exception ex )
{
}
}
private void Btn_Parcourir_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fenetre = new OpenFileDialog();
fenetre.Filter = "Fichiers Audio/*.wma;*.mp3";
fenetre.Title = "Choisissez votre musique";
if (fenetre.ShowDialog().Equals(true ))
{
try
{
try
{
if (lecture == true)
{
Lecteur.Stop();
Lecteur.Dispose();
}
Lecteur = new Audio(fenetre.FileName);
Lecteur.Play();
lecture = true;
pause = false;
}
catch (Exception ex)
{
}
}
catch (Exception ex)
{
}
}
}
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume);
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr hwo, uint dwVolume);
private void trackwave_ValueChanged(object sender, RoutedPropertyChangedEventArgs
{
uint CurrVol = 0;
waveOutGetVolume(IntPtr.Zero, out CurrVol);
ushort CalcVol = (ushort)(CurrVol & 0x0000ffff);
trackwave.Value = CalcVol / (ushort.MaxValue / 10);
double NewVolume = ((ushort.MaxValue / 10) * trackwave.Value);
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) / ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
}
}
}
Mamta MPosted Apr 5, 2011, 5:11 AM
Krishna GaradPosted Apr 5, 2011, 5:08 AM
Chetan NavalePosted Apr 5, 2011, 5:02 AM
Please let me knpw what exacly you are doing. Where you are getting the error.