Answered by:
Media Source in SMFv2

Question
-
hi,
i have used these codes for testing SMFv2 player but my button_click event throws a exception in source setting code!
my codes:
<UserControl x:Class="SMF_Test.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Core="clr-namespace:Microsoft.SilverlightMediaFramework.Core;assembly=Microsoft.SilverlightMediaFramework.Core" xmlns:Media="clr-namespace:Microsoft.SilverlightMediaFramework.Core.Media;assembly=Microsoft.SilverlightMediaFramework.Core" mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800"> <Grid x:Name="LayoutRoot" Background="White"> <Core:SMFPlayer Height="400" Margin="48,100,91,100"> <Core:SMFPlayer.Playlist> <Media:PlaylistItem x:Name="Player"/> </Core:SMFPlayer.Playlist> </Core:SMFPlayer> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="48,515,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </UserControl>
button click event handler:namespace SMF_Test { public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { Player.MediaSource = new Uri("http://localhost:1369/ClientBin/3.wmv"); } } }
my video is in the Client Bin Folder and its build action property is Resource!
Sunday, July 25, 2010 4:51 AM
Answers
-
The syntax you are using is not allowed in the SMFv2. What you need to do is create a new PlaylistItem and put it into the Playlist.
I added x:Name="myPlayer" to this:
<Core:SMFPlayer Height="400" x:Name="myPlayer"
Margin="48,100,91,100">In code, I added these 2 using statements:
using Microsoft.SilverlightMediaFramework.Core;
using Microsoft.SilverlightMediaFramework.Core.Media;Then this is the new code in the button click handler:
PlaylistItem pliTemp = new PlaylistItem();
pliTemp.MediaSource = new Uri(http://localhost:1369/ClientBin/3.wmv);
myPlayer.Playlist[0] = pliTemp;
myPlayer.GoToPlaylistItem(0);Sunday, July 25, 2010 6:19 AM
All replies
-
-
no solve!
my exception:
"Object reference not set to an instance of an object."
Sunday, July 25, 2010 5:17 AM -
Which object in null?
Sunday, July 25, 2010 5:18 AM -
{System.NullReferenceException: Object reference not set to an instance of an object.
at SMF_Test.MainPage.button1_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, String eventName)}Sunday, July 25, 2010 5:22 AM -
Which object in null?
Oops
Should have said
Which object IS null?
Sunday, July 25, 2010 5:22 AM -
Player object
Sunday, July 25, 2010 5:24 AM -
Put a breakpoint on this line:
Player.MediaSource = new Uri("http://localhost:1369/ClientBin/3.wmv");
Which object is null? Player?
Sunday, July 25, 2010 5:24 AM -
Player object!
Sunday, July 25, 2010 5:25 AM -
Your code is getting confused on object keywords. Change x:Name in this
<Media:PlaylistItem x:Name="Player"/>
to something else like myPlaylistItem and then make the same change here
Player.MediaSource = new Uri("http://localhost:1369/ClientBin/3.wmv");
Sunday, July 25, 2010 5:28 AM -
the same exception appear!
Sunday, July 25, 2010 5:30 AM -
I'm trying to duplicate the error here.
Sunday, July 25, 2010 5:51 AM -
i have used SMFv2 and this Documentation: SMFv2
Sunday, July 25, 2010 5:57 AM -
my source project:
Sunday, July 25, 2010 6:02 AM -
Thanks - I've been using SMFv2 since the beta came out in June. But always streaming, not locally hosted files.
I'm still working on it.
Sunday, July 25, 2010 6:05 AM -
The syntax you are using is not allowed in the SMFv2. What you need to do is create a new PlaylistItem and put it into the Playlist.
I added x:Name="myPlayer" to this:
<Core:SMFPlayer Height="400" x:Name="myPlayer"
Margin="48,100,91,100">In code, I added these 2 using statements:
using Microsoft.SilverlightMediaFramework.Core;
using Microsoft.SilverlightMediaFramework.Core.Media;Then this is the new code in the button click handler:
PlaylistItem pliTemp = new PlaylistItem();
pliTemp.MediaSource = new Uri(http://localhost:1369/ClientBin/3.wmv);
myPlayer.Playlist[0] = pliTemp;
myPlayer.GoToPlaylistItem(0);Sunday, July 25, 2010 6:19 AM -
tnx alot snelldl!
it works very well.
Sunday, July 25, 2010 6:29 AM -
pliTemp.MediaSource = new Uri(http://localhost:1369/ClientBin/3.wmv);
Forgot to quote the uri!
pliTemp.MediaSource = new Uri("http://localhost:1369/ClientBin/3.wmv");
Sunday, July 25, 2010 6:29 AM -
Sunday, July 25, 2010 6:30 AM