Witam. Mam prosty programik który teoretycznie działa poprawnie. W praktyce wychodzi jednak iż działa źle. Zadaniem programu jest odtworzenie kolejno plików dźwiękowych wpisanych w textBox-sie np po wpisaniu "plik1+plik2+plik3" program kolejno odtwarza te 3 pliki. I faktycznie tak jest pod warunkiem iż użyjemy debugera w VS. Jeśli jednak uruchomimy program normalnie wtedy odtwarza tylko ostatni plik.
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;
namespace SyntMowy
{
public partial class Form1 : Form
{
int a = 1;
string[] sTab2;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public void dzwiek(string nazwaPliku)
{
System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
myPlayer.SoundLocation = System.Environment.CurrentDirectory.ToString() + @"\alofony1\" + nazwaPliku + ".wav";
myPlayer.Play();
}
public string[] podziel(string tekst)
{
int dlt = tekst.Length;
int x = 0;
for (int i = 0; i < dlt; i++)
{
if (tekst[i] == '+')
{
a++;
}
}
string[] sTab = new string[a];
for (int i = 0; i < dlt; i++)
{
if (tekst[i] != '+')
{
sTab[x] += tekst[i];
}
else
{
x++;
}
}
return sTab;
}
private void button1_Click(object sender, EventArgs e)
{
sTab2 = new string[100];
sTab2 = podziel(textBox1.Text);
for (int i = 0; i < a; i++)
{
dzwiek(sTab2[i]);
}
sTab2 = null;
a = 1;
}
}
}