Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows phone 7 在进入下一首歌曲之前,遍历枚举并检查MediaPlayer的状态_Windows Phone 7_Media Player_Ienumerator - Fatal编程技术网

Windows phone 7 在进入下一首歌曲之前,遍历枚举并检查MediaPlayer的状态

Windows phone 7 在进入下一首歌曲之前,遍历枚举并检查MediaPlayer的状态,windows-phone-7,media-player,ienumerator,Windows Phone 7,Media Player,Ienumerator,我需要在我的IEnumerable集合中播放歌曲,但是这种方法有很多问题。如果我使用计时器检查MediaState,它可能会工作,但是当我从此页面导航时,该类将被取消,音乐将停止。我想这样做的原因是能够播放来自不同专辑的歌曲: 我的代码: private SongCollection mySongCollection; IEnumerable<Song> ultimateCollection; mySongCollection = library.Album

我需要在我的IEnumerable集合中播放歌曲,但是这种方法有很多问题。如果我使用计时器检查MediaState,它可能会工作,但是当我从此页面导航时,该类将被取消,音乐将停止。我想这样做的原因是能够播放来自不同专辑的歌曲:

我的代码:

    private SongCollection mySongCollection;
    IEnumerable<Song> ultimateCollection;

    mySongCollection = library.Albums[index].Songs;
    ultimateCollection = mySongCollection.Concat(library.Albums[1].Songs);

    foreach (Song a in ultimateCollection)
      {
      while (MediaPlayer.State == MediaState.Playing || MediaPlayer.State == MediaState.Paused)
                    {
                       //while MediaState still playing, dont play next song
                    }
                        MediaPlayer.Play(a);
       }
private SongCollection mySongCollection;
IEnumerable终极集合;
mySongCollection=library.Albums[index]。歌曲;
ultimateCollection=mySongCollection.Concat(library.Albums[1].歌曲);
foreach(终极精选中的歌曲a)
{
while(MediaPlayer.State==MediaState.Playing | | MediaPlayer.State==MediaState.Paused)
{
//当MediaState还在播放时,不要播放下一首歌
}
MediaPlayer.Play(a);
}

如果我理解正确,您希望在离开页面后保留收藏
最终收藏。在您的示例中,它被销毁是有意义的,因为它是页面的一个字段变量。你想要做的是有一个静态播放列表,可以从你的应用程序的任何地方访问

我建议将
ultimateCollection
移动到App.xaml

public IList<Song> UltimateCollection {get; private set;}

// and then somewhere else in App.xaml.cs where your player is looping through the songs
    int i=0;
    while(i<UltimateCollection.Count)
    {
        Song a = UltimateCollection[i];
        MediaPlayer.Play(a);
        while (MediaPlayer.State == MediaState.Playing || MediaPlayer.State == MediaState.Paused)
        {
            //while MediaState still playing, dont play next song
        }
    }
添加到收藏时可能会出现一些线程问题,但这应该允许您将歌曲添加到播放列表中,并导航到页面之外。让我知道这是否有帮助

干杯,
所有。

如果我理解正确,您希望在离开页面后保留收藏
最终收藏。在您的示例中,它被销毁是有意义的,因为它是页面的一个字段变量。你想要做的是有一个静态播放列表,可以从你的应用程序的任何地方访问

我建议将
ultimateCollection
移动到App.xaml

public IList<Song> UltimateCollection {get; private set;}

// and then somewhere else in App.xaml.cs where your player is looping through the songs
    int i=0;
    while(i<UltimateCollection.Count)
    {
        Song a = UltimateCollection[i];
        MediaPlayer.Play(a);
        while (MediaPlayer.State == MediaState.Playing || MediaPlayer.State == MediaState.Paused)
        {
            //while MediaState still playing, dont play next song
        }
    }
添加到收藏时可能会出现一些线程问题,但这应该允许您将歌曲添加到播放列表中,并导航到页面之外。让我知道这是否有帮助

干杯,
艾尔。

谢谢你,阿吉姆。事实上,当我说从这个页面导航时,我的意思是当用户离开我的应用程序或关闭屏幕时。我真正想要的是把我的歌曲列表放在后台播放,就像后台音频代理一样。谢谢ajm。事实上,当我说从这个页面导航时,我的意思是当用户离开我的应用程序或关闭屏幕时。我真正想要的是把我的歌曲列表像背景音频代理一样播放背景音乐。