簡體   English   中英

如何從手機和SD卡中獲取音頻文件並進行播放?

[英]How to fetch audio files from phone and SD card and play them?

如何從手機和SD卡中獲取音頻文件並進行播放? 我只是一個設計師,但是看到代碼我就會明白。

所以我需要的是一個能做到這一點的代碼

Petzold向我們展示了這一點。 按下一個按鈕,從庫中播放隨機曲調。

XAML:

            <Button Content="Button" HorizontalAlignment="Left" Margin="177,160,0,0" VerticalAlignment="Top"/>

后面的C#代碼:

使用Microsoft.Xna.Framework.Media;

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        Random random = new Random();  // new random variable
        MediaLibrary mediaLib = new MediaLibrary(); // this is where it grabs your whole music library and enumerates everything.  If you break here, you can see it.

        AlbumCollection albums = mediaLib.Albums;  // pick which song you want.
        Album album = albums[random.Next(albums.Count)];
        SongCollection songs = mediaLib.Songs;
        Song song = songs[random.Next(songs.Count)];
        MediaPlayer.Play(song); // this plays the song.
    }

就這么簡單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM