【问题标题】:MediaElement is playing audio only in debug mode, its not playing audio without debug modeMediaElement 仅在调试模式下播放音频,在没有调试模式的情况下不播放音频
【发布时间】:2014-06-26 19:18:55
【问题描述】:

我正在使用 windows phone 8 尝试通过创建用户控件和媒体元素来在我的应用中实现音频播放功能。

令人惊讶的是,在调试期间正在播放音频,但是当我在没有调试模式的情况下运行应用程序时,音频无法播放,我尝试了 await 和 async 方法,但那也不起作用。

MainPage.xaml.cs

private async void AudioControl(string audioId, string audio_url)
{
   customControlAudioPlayer.media_Id = audioId;
   customAudioPlayer.media_Url = audio_url;
   //Following function is dedicated to show control and play the audio.
   await customAudioPlayer.RenderView();
   gridContainsMediaElement.Visibility = Visibility.Visible;
}

MainPage.xaml

xmlns:MyControls="clr-namespace:dbok.Controls"

<Grid Name="gridContainsMediaElement"  
      VerticalAlignment="Top"  
      Background="Black" Visibility="Collapsed">
        <MyControls:AudioPlayerControl 
           x:Name="customControlAudioPlayer"/>
       <!--CloseClick="audioPlayerControl_CloseClick"-->
</Grid>

CustomControlPlayer.xaml

 <Grid Background="{StaticResource PhoneChromeBrush}"  >

        <MediaElement x:Name="audioMediaElement" AutoPlay="False" 
            Grid.Row="0" 
            MediaOpened="audioMediaElement_MediaOpened"
            MediaEnded="audioMediaElement_MediaEnded"
                    MediaFailed="audioMediaElement_MediaFailed"
            HorizontalAlignment="Center" Height="05" 
            VerticalAlignment="Center"/>

    <Slider Visibility="Visible" Margin="50,0,50,0"
            x:Name="mediaPositionSlider" Background="#f1592a" 
            Minimum="0" Grid.Row="0" 
            />

    </StackPanel>
</Grid>

CustomControlPlayer.xaml.cs

 public string media_Id;
 public string media_Url;

 public async Task RenderView()
 {
    Uri file_url;
    if (Uri.TryCreate(media_Url, UriKind.Absolute, out file_url))
    {
        myElement.Source = file_url;
        myElement.Play();

        //I tried by check the media element state but its executing and playing only in debug mode. it was not working for me without debug i made it commented.
        //if (myElement.CurrentState != MediaElementState.Playing)
        //{
        //    myElement.Play();
        //}
        mediaPositionSlider.Value = 0;
        UpdateDuration(0);
   }

//-----------

private void UpdateDuration(double _myValue)
{
    TimeSpan t = TimeSpan.FromSeconds(_myValue);
    string time_slot = string.Format("{0:D2}:{1:D2}:{2:D2}",
                   t.Hours,
                   t.Minutes,
                   t.Seconds);
    PlayStatusLabel.Text = time_slot.ToString();
}

我已经发布了我的代码,我在哪里以及我做错了什么,它没有在运行模式而不是调试模式下播放?

【问题讨论】:

    标签: debugging audio windows-phone-8 mediaelement audio-player


    【解决方案1】:

    我已经成功解决了我面临的问题,实际上当光标到达 audioMediaElement.Play(); 时会发生什么; Play() 函数需要时间在内部执行,我做了什么,我将 audioMediaElement.Play() 替换为 audioMediaElement.AutoPlay = true;它开始工作了。 :) 呜呜呜…… :)

    【讨论】:

      猜你喜欢
      • 2012-03-04
      • 2015-03-10
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 2016-11-23
      • 1970-01-01
      • 2015-10-14
      相关资源
      最近更新 更多