gpt4 book ai didi

c# - 如何从手机和SD卡中获取音频文件并进行播放?

转载 作者:行者123 更新时间:2023-12-03 02:12:37 25 4
gpt4 key购买 nike

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

就这么简单。

关于c# - 如何从手机和SD卡中获取音频文件并进行播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22813011/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com