v MainPage.xaml
1 2 3 4 5 6 7 8 9 |
<Grid.ColumnDefinitions> <ColumnDefinition> </ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition> </RowDefinition> </Grid.RowDefinitions> <MediaElement x:Name="me" Grid.Column="0" Grid.Row="0" IsMuted="False" Volume="100" AudioCategory="ForegroundOnlyMedia" PosterSource="Assets/Logo.png" RealTimePlayback="False" AutoPlay="True" Height="100" Width="100"> </MediaElement> |
4. Vlozte tento kod tridy MainPage v MainPage.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
IRandomAccessStreamWithContentType stream = null; void OpenSong() { Windows.Storage.KnownFolders.MusicLibrary.GetFileAsync("_.mp3").Completed = (async, status) => { if (async.Status == AsyncStatus.Completed) { StorageFile sf = async.GetResults(); sf.OpenReadAsync().Completed = (async2, status2) => { if (async2.Status == AsyncStatus.Completed) { stream = (IRandomAccessStreamWithContentType)async2.GetResults(); this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, PlaySong).Completed = (async3, status3) => { }; } }; } }; } void PlaySong() { //-Nastavit pouze vlastnost Source nestaci, pak mi to nechtelo hrat, musi se to pres metodu SetSource me.SetSource(stream, stream.ContentType); me.Play(); } |
5. Zavolejte metodu OpenSong() v prazdne metode OnNavigatedTo(). Pokud ji zavolate v konstruktoru, nevyhodi se vam zadna chyba ale zvuk vam proste nebude hrat
1 2 3 4 |
protected override void OnNavigatedTo(NavigationEventArgs e) { OpenSong(); } |
6. Vytvorte hudebni soubor _.mp3 v hudebni knihovne W8 7. Povolte v souboru Package.appxmanifest pristup do hudebni knihovny 8. Spustte program a otestujte]]>