mercredi 24 juin 2015

Shuffle Function with Checkbox - C#

What I need is a checkbox to activate or deactivate the random playback from tracks in a playlist (datatable). If the checkbox is checked and a playing track ended the next random track should start playing automatically.

Heres my event which is automatically called when a track has ended:

    // This event is automatically called when a track has ended

    private void mePlayer_MediaEnded(object sender, RoutedEventArgs e)
    {

        // Check, if the the (last calculated) Index is in the datagrid range
        // -1 is used, cause the indexes starts by 0 not 1

        if (newIndex >= (dgPlayList.Items.Count - 1)) 
        {
            // If the end of the datagrid is reached, set index to 0 for playing the first track

            newIndex = 0;
        }
        else
        {
            // Is there a following track in the datagrid, then use the next calculated index

            newIndex += 1;
        }

        Console.WriteLine("Set index to: " + newIndex);

        // Tell the media player to use the calculated nexIndex

        mePlayer.Source = new Uri(playList.Rows[newIndex]["Dateiname"].ToString());
        lblFileName.Content = getFileName(playList.Rows[newIndex]["Dateiname"].ToString());

        // Starts to play and set it to play

        mePlayer.Play();
        isPlaying = true;

    }

Im pretty new to C# and I just don't know how to integrate that the player plays a random track after a track has ended.

Hope anybody can help me with this issue. Thanks!




Aucun commentaire:

Enregistrer un commentaire