언어 C # 뒤에있는 코드와 XAML의 디자인을 사용하여 Windows Phone 8에서 음악 플레이어를 만들고 싶습니다. 휴대폰의 mp3 파일 목록을 하나의 창에 표시하고 싶습니다.
전화의 mp3 파일 목록을 하나의 창에 표시하려면 어떻게합니까?
음, 전화 미디어 라이브러리에있는 노래 목록을 만들고 싶다면
기본 클래스 SongModel 만들기
public class SongModel
{
public int songId { get; set; }
public string songName { get; set; }
}
전역 변수 만들기
MediaLibrary mLibrary = new MediaLibrary();
SongCollection songs;
List<SongModel> songnames;
이제 페이지 생성자에서 다음 코드 줄을 작성하십시오.
songs = mLibrary.Songs;
MediaPlayer.ActiveSongChanged += MediaPlayer_ActiveSongChanged;
MediaPlayer.MediaStateChanged += MediaPlayer_MediaStateChanged;
if (songs.Count != 0)
{
songnames = new List<SongModel>();
for (int i = 0; i < songs.Count; i++)
{
songnames.Add(new SongModel() { songName = songs[i].Name, songId = i });
}
lbMusic.ItemsSource = songnames; // lbMusic is the list/listbox here
}
목록 상자 lbMusic의 xaml
<ListBox SelectionChanged="lbMusic_SelectionChanged" Foreground="Black" FontWeight="Bold" Name="lbMusic" Height="210" Width="480" Margin="0,10,0,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,5,0,5" Width="480" Background="White" Height="40">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Left" Text="{Binding songName}" TextTrimming="WordEllipsis" Margin="30,0,0,0" Tag="{Binding songId}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
노래 ID를 기준으로 노래를 재생하려면 목록 상자의 selectionChanged 이벤트를 무시하십시오.
private void lbMusic_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
try
{
if (lbMusic.SelectedIndex != -1)
{
int musicId = (lbMusic.SelectedItem as SongModel).songId;
MediaPlayer.Play(songs, musicId);
}
}
catch
{
MessageBox.Show(TextResources.resErrorActiveSong);
}
}
예상대로 도움이 되었기를 바랍니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다