积极答复者
问个关于 NullReferenceException 的问题

问题
-
用的SMF框架
<smf:SMFPlayer Style="{StaticResource SMFPlayerStyle1}" Grid.Row="1" Height="420" Width="680">
<smf:SMFPlayer.Playlist>
<Media:PlaylistItem VideoStretchMode="Uniform" x:Name="smfPlaylistItem" DeliveryMethod="AdaptiveStreaming" MediaSource="http://ecn.channel9.msdn.com/o9/content/smf/smoothcontent/bbbwp7/big buck bunny.ism/manifest" />
</smf:SMFPlayer.Playlist>
</smf:SMFPlayer>创建了一个按钮触发全屏操作
private void Button_Click(object sender, RoutedEventArgs e)
{
smfPlaylistItem.VideoStretchMode = Stretch.Fill;
}然后就报 NullReferenceException 异常 ,异常信息如下:
System.NullReferenceException was unhandled
Message=NullReferenceException
StackTrace:
at SMFBlendTest.MainPage.Button_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp
(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl,
EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr
unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)在网上没搜到好的解决方案,望牛逼的哥们不吝赐教,谢谢!
答案
-
你好,
抛出异常的原因是smfPlaylistItem不在当前的NameScrope内所以没有办法直接通过名字获取SmfPlaylistItem,解决方案请参考以下代码
private void button1_Click(object sender, RoutedEventArgs e) { PlaylistItem item = player.Playlist[0] as PlaylistItem; item.VideoStretchMode = Stretch.Uniform; player.GoToPlaylistItem(0); }
- 已标记为答案 鲁大宝 2012年7月26日 1:31
-
你好,
不让播放器跳回到片头的解决方法就是记录一下当前的位置,然后在播放PlaylistItem前设定一下其StartPosition。
private void button1_Click(object sender, RoutedEventArgs e) { player.Pause(); PlaylistItem item = player.Playlist[0] as PlaylistItem; item.VideoStretchMode = Stretch.Uniform; item.StartPosition = player.PlaybackPosition;//设置起始播放位置为当前位置 player.GoToPlaylistItem(0); }
- 已标记为答案 鲁大宝 2012年7月26日 6:12
全部回复
-
你好,
抛出异常的原因是smfPlaylistItem不在当前的NameScrope内所以没有办法直接通过名字获取SmfPlaylistItem,解决方案请参考以下代码
private void button1_Click(object sender, RoutedEventArgs e) { PlaylistItem item = player.Playlist[0] as PlaylistItem; item.VideoStretchMode = Stretch.Uniform; player.GoToPlaylistItem(0); }
- 已标记为答案 鲁大宝 2012年7月26日 1:31
-
你好,
不让播放器跳回到片头的解决方法就是记录一下当前的位置,然后在播放PlaylistItem前设定一下其StartPosition。
private void button1_Click(object sender, RoutedEventArgs e) { player.Pause(); PlaylistItem item = player.Playlist[0] as PlaylistItem; item.VideoStretchMode = Stretch.Uniform; item.StartPosition = player.PlaybackPosition;//设置起始播放位置为当前位置 player.GoToPlaylistItem(0); }
- 已标记为答案 鲁大宝 2012年7月26日 6:12