PDA

View Full Version : [c#] lettore mp3 per pocketpc (windows mobile 6)


Cipollina87
07-07-2010, 09:40
Ciao a tutti!!
sto iniziando a programmare un'applicazione per palmare in c# con Microsoft Visual Studio 2008!
L'applicazione sarà un mp3 player!! tipo windows media player!!
M trovo in difficoltà perchè non so come fare a riprodurre un file mp3!!

ho trovato questo
e funziona benissimo

using System.Threading;
using System.Runtime.InteropServices;
string filename = "";
string path2 = "";

public Form1()
{
InitializeComponent();
}

[DllImport("aygshell.dll")]
static extern uint SndOpen(string pszSoundFile, ref IntPtr phSound);

[DllImport("aygshell.dll")]
static extern uint SndPlayAsync(IntPtr hSound, uint dwFlags);

[DllImport("aygshell.dll")]
static extern uint SndClose(IntPtr hSound);

[DllImport("aygshell.dll")]
static extern uint SndStop(int SoundScope, IntPtr hSound);

[DllImport("aygshell.dll")]
static extern uint SndPlaySync(string pszSoundFile, uint dwFlags);

const int SND_SCOPE_PROCESS = 0x1;

string mySoundLocation = string.Empty;

public string SoundLocation
{
get { return mySoundLocation; }
set { mySoundLocation = value; }
}

IntPtr mySound = IntPtr.Zero;
Thread myThread = null;
public void PlayLooping()
{
myThread = new Thread(() =>
{
while (true)
{
SndPlaySync(mySoundLocation, 0);
}
}
);
myThread.Start();
}

public void Play()
{
SndOpen(mySoundLocation, ref mySound);
SndPlayAsync(mySound, 0);
}

public void Stop()
{
if (myThread != null)
{
SndStop(SND_SCOPE_PROCESS, IntPtr.Zero);
myThread.Abort();
myThread = null;
}
if (mySound != IntPtr.Zero)
{
SndStop(SND_SCOPE_PROCESS, IntPtr.Zero);
SndClose(mySound);
mySound = IntPtr.Zero;
}
}


private void FindFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();

if (ofd.ShowDialog() == DialogResult.OK)
{
filename = System.IO.Path.GetFileName(ofd.FileName);
path2 = System.IO.Path.GetDirectoryName(ofd.FileName);
}
FileName.Text = path2 + "\\" + filename;
}

private void BtnPlay_Click(object sender, EventArgs e)
{
mySoundLocation = FileName.Text;
Play();
}

private void BtnStop_Click(object sender, EventArgs e)
{
Stop();
}





Ora il mio problema è che non riesco a mettere in pausa l'mp3!