I am developing an app on windows mobile 6 using c#. There is a audio playing feature in my app and I implement it by opennetcf. Everything is great except that when I play a wav file, the screen will be locked while the sound is still playing after 5 second. However, I hope to implement a timecount feature which shows how long the voice has been played. Here is my code.
public partial class voicePlayer : Form
{
public voicePlayer()
{
InitializeComponent();
player = new Player();
player.DonePlaying += new WaveDoneHandler(player_DonePlaying);
timer = new Timer();
timer.Interval = 1000;
timer.Enabled = false;
timer.Tick += new EventHandler(refreshTime);
}
private Timer timer;
private Player player;
private Stream stream;
private DateTime startTime;
private bool pause = false;
private int timeCount;
private void voicePlayer_Activated(object sender, EventArgs e)
{
play.Enabled = true;
stop.Enabled = false;
pause = false;
play.Text = "Play";
}
void refreshTime(object sender, EventArgs e)
{
timeCount++;
time.Text = string.Format("{0:00:00:00}", timeCount);
if (!player.Playing && !pause)
{
timeCount = 0;
pause = false;
timer.Enabled = false;
play.Text = "Play";
stop.Enabled = false;
time.Text = "00:00:00";
}
}
private void play_Click(object sender, EventArgs e)
{
if (!pause && play.Text == "Play")
{
play.Text = "Pause";
stop.Enabled = true;
timer.Enabled = true;
stream = File.OpenRead(Form1.note);
player.Play(stream);
startTime = DateTime.Now;
}
else if (!pause && play.Text == "Pause")
{
player.Pause();
play.Text = "Play";
pause = true;
timer.Enabled = false;
}
else
{
pause = false;
play.Text = "Pause";
player.Restart();
timer.Enabled = true;
}
}
void player_DonePlaying(object sender, IntPtr wParam, IntPtr lParam)
{
}
private void stop_Click(object sender, EventArgs e)
{
player.Stop();
pause = false;
}
}
Thanks for help.