Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the MediaPlayer in my program.

C#
internal MediaPlayer player = new MediaPlayer();
List<string> MP3FilesNames = Directory.GetFiles(@"Audio Files", "*.mp3").ToList<string>();

for (i = 0; i < MP3FilesNames.Count; i++)
{
	player.Open(new Uri(MP3FilesNames[i], UriKind.Relative));
	player.Play();
}

In "Audio Files" directory are from 20 to 100 mp3 files. Each file has an audio duration of 1-2 seconds. How can I organize repeat of one file 4-5-6 or 7 times?

What I have tried:

I am looking for the possibility of repeated repetition.
Posted
Updated 16-May-20 0:21am

1 solution

Monitor the MediaPlayer for when the audio track ends: then start it again. Repeat as many times as you need.

This may help: MediaPlayer.MediaEnded Event (Windows.Media.Playback) - Windows UWP applications | Microsoft Docs[^]
 
Share this answer
 
Comments
Member 12618031 16-May-20 11:57am    
Thanks for the answer. I set the handler. Now everything works.

player.MediaEnded += new EventHandler(Media_Ended);

private void Media_Ended(object sender, EventArgs e)
{
player.Position = TimeSpan.Zero;
player.Play();
}
OriginalGriff 16-May-20 12:05pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900