none
[U8.1]Simple music player!?

    Question

  • Can someone plz explain to me, how i make it change music number ?

    I tried with assigning the buttons. But that gives me issues, i dont know the code for Play.sound.Next();

    <GridBackground="{ThemeResourceApplicationPageBackgroundThemeBrush}">

    <MediaElementName="sound1"Source="Music/Sound.mp3"AutoPlay="False"/>

    <MediaElementName="sound2"Source="Music/Sound2.mp3"AutoPlay="False"/>

    <MediaElementName="sound3"Source="Music/Sound3.mp3"AutoPlay="False"/>

    <MediaElementName="sound4"Source="Music/Sound4.mp3"AutoPlay="False"/>

    </Grid>

    <Page.BottomAppBar>

    <AppBar>

    <GridHeight="150">

    <Grid.ColumnDefinitions>

    <ColumnDefinition/>

    <ColumnDefinition/>

    </Grid.ColumnDefinitions>

    <StackPanelOrientation="Horizontal">

    </StackPanel>

    <StackPanelGrid.Column="1"HorizontalAlignment="Right"Orientation="Horizontal"/>


    <AppBarButtonGrid.Column="1"HorizontalAlignment="Right"Icon="Play"Label="Afspil"Margin="0,30,100,0"VerticalAlignment="Top"Click="AppBarButton_Click"/>

    <AppBarButtonGrid.Column="1"HorizontalAlignment="Right"Icon="Pause"Label="Pause"Margin="0,30,200,0"VerticalAlignment="Top"/>

    <AppBarButtonGrid.Column="1"HorizontalAlignment="Right"Icon="Next"Label="Næste"Margin="0,30,0,0"VerticalAlignment="Top"Click="AppBarButton_Click_1"/>

    <AppBarButtonGrid.Column="1"HorizontalAlignment="Right"Icon="Previous"Label="AppBarButton"Margin="0,30,300,0"VerticalAlignment="Top"/>

    </Grid>

    </AppBar>

    </Page.BottomAppBar>

    Friday, July 24, 2015 2:06 AM

Answers

  • Hi Noobsie,

    >>how i make it change music number?

    Generally, if you need to play several music files, we can maintain a List to switch the current playing music, see this officil sample: https://code.msdn.microsoft.com/windowsapps/Basic-Media-Playback-003619be/sourcecode?fileId=44705&pathId=797575364

    The 5th scenario adds Handler for the MediaEnded event of the MediaElement to change ListBox's SelectedIndex, while in SelectionChanged handler, change the source of MediaElement:

    /// <summary> 
    /// Handler for the MediaEnded event of the MediaElement. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private void MediaElement_MediaEnded(object sender, RoutedEventArgs e) 
    { 
        // Advance to the next file in the playlist if any remain 
        if (Playlist.SelectedIndex < Playlist.Items.Count - 1) 
        { 
            Playlist.SelectedIndex++; 
        } 
    } 
     
    /// <summary> 
    /// Selection changed handler for the playlist ListBox. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private async void Playlist_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
        StorageFile file = Playlist.SelectedItem as StorageFile; 
     
        if (file != null) 
        { 
            // Open the selected file and set it as the MediaElement's source 
            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); 
            Scenario5MediaElement.SetSource(stream, file.ContentType); 
        } 
    }

    I noticed that you have four MediaElement controls, you can also use Switch Case statement to control one control to play music.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 27, 2015 6:05 AM
    Moderator

All replies

  • Friday, July 24, 2015 6:11 AM
  • Hi. And thank you, im new in here...

    My Platform.. I think it is [U8.1]?   Universal Windows8.1 and Phone8.1

    I use XAML and C#

    Friday, July 24, 2015 1:09 PM
  • Hi. And thank you, im new in here...

    My Platform.. I think it is [U8.1]?   Universal Windows8.1 and Phone8.1

    I use XAML and C#


    My platform IS [U8.1]
    Friday, July 24, 2015 4:02 PM
  • Hi Noobsie,

    >>how i make it change music number?

    Generally, if you need to play several music files, we can maintain a List to switch the current playing music, see this officil sample: https://code.msdn.microsoft.com/windowsapps/Basic-Media-Playback-003619be/sourcecode?fileId=44705&pathId=797575364

    The 5th scenario adds Handler for the MediaEnded event of the MediaElement to change ListBox's SelectedIndex, while in SelectionChanged handler, change the source of MediaElement:

    /// <summary> 
    /// Handler for the MediaEnded event of the MediaElement. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private void MediaElement_MediaEnded(object sender, RoutedEventArgs e) 
    { 
        // Advance to the next file in the playlist if any remain 
        if (Playlist.SelectedIndex < Playlist.Items.Count - 1) 
        { 
            Playlist.SelectedIndex++; 
        } 
    } 
     
    /// <summary> 
    /// Selection changed handler for the playlist ListBox. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private async void Playlist_SelectionChanged(object sender, SelectionChangedEventArgs e) 
    { 
        StorageFile file = Playlist.SelectedItem as StorageFile; 
     
        if (file != null) 
        { 
            // Open the selected file and set it as the MediaElement's source 
            IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.Read); 
            Scenario5MediaElement.SetSource(stream, file.ContentType); 
        } 
    }

    I noticed that you have four MediaElement controls, you can also use Switch Case statement to control one control to play music.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, July 27, 2015 6:05 AM
    Moderator