1
Vote

MediaUriElement seeks automatically to the end of song.

description

Hi all,I have faced a strange problem, i have a list of songs in a list. When media ends i want the next song to play. strange part is, it gets next song as source but plays only 1 or 2 seconds then jumps to next song. i mean automatically media seeks to the end of song and then jumps to the next one(i mean media ends after 1 or 2 seconds immediately after it starts).

comments

yulbas wrote Jul 4, 2015 at 8:11 PM

it happens specially when i manually seek the media position, then it happens when playing the next video.

yulbas wrote Jul 5, 2015 at 5:04 AM

Code Behind for playing next song after Media Ended
private void mediaPlayerMain_MediaEnded(object sender, RoutedEventArgs e)
    {
        try
        {
            ValidateData.Instance.selectedItem = SongCollection.Instance.songs.ElementAt(SongCollection.Instance.songs.IndexOf(ValidateData.Instance.selectedItem) + 1);
        }
        catch (IndexOutOfRangeException)
        {
            ValidateData.Instance.selectedItem = SongCollection.Instance.songs[0];

        }
        playSelectedItem();
    }
    public void playSelectedItem()
    {
        try
        {
            if (live.VideoCaptureDevice != null)
                closelive();
            if (File.Exists(ValidateData.Instance.selectedItem.Path))
            {

                mediaPlayerMain.Source = new Uri(ValidateData.Instance.selectedItem.Path);
                mediaPlayerMain.Play();
            }
            else
            {
                mediaPlayerMain_MediaEnded(null, null);
            }
        }
        catch (Exception)
        {

        }
    }