我已经使用MyToolkit在我的Windows phone 8应用程序中嵌入Youtube视频它可以正常使用网络连接但是当我关闭WiFi并在我的应用程序中启动视频时它会崩溃,所以我想显示一条消息告诉我用户“没有网络连接”并导航回“MainPage.xaml”而不是崩溃,这是我使用的代码
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
var videoUri = await MyToolkit.Multimedia.YouTube.GetVideoUriAsync("Youtube_ID", MyToolkit.Multimedia.YouTubeQuality.Quality480P, MyToolkit.Multimedia.YouTubeQuality.Quality480P);
if (videoUri != null)
player.Source = videoUri.Uri;
}
这是Xaml代码
<Grid HorizontalAlignment="Stretch" Height="Auto" VerticalAlignment="Top" Width="Auto">
<mmppf:MediaPlayer x:Name="player" HorizontalAlignment="Stretch" Width="Auto"/>
</Grid>
由于
答案 0 :(得分:1)
试试这个 var videoUri = await MyToolkit.Multimedia.YouTube.GetVideoUriAsync(&#34; Youtube_ID&#34;,MyToolkit.Multimedia.YouTubeQuality.Quality480P)
答案 1 :(得分:0)
在try catch中围绕你的await方法:
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
bool videoSuccess = true;
try {
var videoUri = await MyToolkit.Multimedia.YouTube.GetVideoUriAsync("Youtube_ID", MyToolkit.Multimedia.YouTubeQuality.Quality480P, MyToolkit.Multimedia.YouTubeQuality.Quality480P);
if (videoUri != null)
player.Source = videoUri.Uri;
}
catch (Exception e) { // Debug and find out which exception is being thrown
videoSuccess = false;
}
if (videoSuccess == false) {
await MessageDialog.ShowAsync("Video couldn't be played.","No Internet"); }
}