如何从手机和SD卡中获取音频文件并播放它们

本文关键字:文件 音频 播放 获取 手机 SD | 更新日期: 2023-09-27 17:50:26

如何从手机和SD卡中获取音频文件并播放?我只是一个设计师,但是当我看到代码时,我能理解它。

所以我需要的是一个代码来完成这个

如何从手机和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.
    }