Windows phone 8 在WindowsPhone8中播放YouTube视频
我已经解析了RSS提要 并在水平滚动视图中显示歌曲图片,如下所示 现在,当我点击一张特定的图片时,它应该在上面的空白处播放 Xaml的代码是Windows phone 8 在WindowsPhone8中播放YouTube视频,windows-phone-8,Windows Phone 8,我已经解析了RSS提要 并在水平滚动视图中显示歌曲图片,如下所示 现在,当我点击一张特定的图片时,它应该在上面的空白处播放 Xaml的代码是 <phone:PhoneApplicationPage x:Class="PhoneApp1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.c
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:delay="clr-namespace:Delay;assembly=PhonePerformance"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Teluguone" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Songs" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="player" AutoPlay="True" Margin="0,0,0,282"/>
<ScrollViewer HorizontalScrollBarVisibility="Hidden" Height="Auto" Margin="0,411,0,63" >
<ListBox x:Name="videosongList" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="168" Width="412" SelectionChanged="videosongList_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,50,0,0" Orientation="Horizontal">
<Image x:Name="img1" Source="{Binding songpic}" ></Image>
<!--<TextBlock Text="{Binding songname}" TextWrapping="Wrap" VerticalAlignment="Bottom"
FontSize="20" />-->
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel >
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</ScrollViewer>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
Songsdetails.cs
Videosongs.cs
我已经试了很多天了。如果我出了问题,请任何人帮助我
我是这方面的初学者,无法理解为什么会出现bug
提前感谢。您遇到了什么类型的错误?System.Threading.Tasks.dll中发生了类型为“System.NullReferenceException”的未处理异常。y.dll中发生了类型为“System.NullReferenceException”的首次机会异常。中发生了类型为“System.NullReferenceException”的首次机会异常System.Threading.Tasks.dll。如果我出错,请告诉我。这意味着当方法需要对象时,某个变量的值为空。我希望song或song.songcode为空。非常感谢。songcode为空。现在我得到了解决方案
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
Songsdetails song;
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(VideosongsDownloaded);
downloader.DownloadStringAsync(uri);
}
void VideosongsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
try
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
XmlSerializer serializer = new XmlSerializer(typeof(videosongs));
videosongs Videosongs = (videosongs)serializer.Deserialize(document.CreateReader());
videosongList.ItemsSource = Videosongs.Collection;
}
}
catch (Exception ex)
{
//MessageBox.Show(ex.InnerException.Message);
MessageBox.Show(ex.ToString());
}
}
private void videosongList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var app = App.Current as App;
app.selectedSongsdetails = (Songsdetails)videosongList.SelectedItem;
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
var app = App.Current as App;
song = app.selectedSongsdetails;
var url = await YouTube.GetVideoUriAsync(song.songcode, YouTubeQuality.Quality480P);
player.Source = url.Uri;
}
}
}
public class Songsdetails
{
[XmlElement("songname")]
public string songname { get; set; }
[XmlElement("songpic")]
public string songpic { get; set; }
[XmlElement("songurl")]
public string songurl { get; set; }
[XmlElement("songcode")]
public string songcode { get; set; }
[XmlElement("songdescr")]
public string songdescr { get; set; }
[XmlElement("songtitletags")]
public string songtitletags { get; set; }
[XmlElement("songmetatags")]
public string songmetatags { get; set; }
[XmlElement("songmetadesc")]
public string songmetadesc { get; set; }
[XmlElement("songdate")]
public string songdate { get; set; }
}
}
namespace PhoneApp1
{
[XmlRoot("videosongs")]
public class videosongs
{
[XmlElement("songsdetails")]
public ObservableCollection<Songsdetails> Collection { get; set; }
}
}
var url = await YouTube.GetVideoUriAsync(song.songcode, YouTubeQuality.Quality480P);