Silverlight播放器 一
引入命名空间 Microsoft.Web.Media.SmoothStreaming
该DLL下可以使用播放器控件ssme,直接支持平滑播放。SMF播放器(PPPMF)也是以ssme为核心的播放器。
插入播放器页面代码
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2"
width="480" height="400">
<param name="splashscreensource" value="SplashScreen.xaml" />
<param name="onSourceDownloadProgressChanged" value="onSourceDownloadProgressChanged" />
<param name="source" value="ClientBin/SilverlightApplication5.xap" />
<param name="onerror" value="onSilverlightError" />
<param name="background" value="Black" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<param name="InitParams" value="broadcastUrl=http://sl2.jstv.com/jiangsuweishi.isml/Manifest" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkID=161376" alt="获取 Microsoft Silverlight"
style="border-style: none" />
</a>
</object>
<iframe id='_sl_historyFrame' style='visibility: hidden; height: 0; width: 0; border: 0px'>
</iframe>
</div>
silverlight中接受传入参数InitParams代码
public static string mediaurl;
private void Application_Startup(object sender, StartupEventArgs e)
{
_dic = e.InitParams;
mediaurl = e.InitParams["broadcastUrl"].ToString().Trim();
this.RootVisual = new MainPage(_dic);
}
后台指定直播点
public MainPage(IDictionary<string, string> dicParam)
{
InitializeComponent();//该句应该放在该函数里第一行,否则报错
_isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape");
//dicParam.TryGetValue("broadcastUrl", out PlayUri);
Me.SmoothStreamingSource = new Uri(App.mediaurl);
label1.Content = PlayUri.ToString();
// 为初始化变量所必需
C.Width = player_width;
C.Height = player_height + 40;
Me.Width = player_width;
Me.Height = player_height;
StackControl.Width = player_width;
label1.Content = ie_width.ToString() + ":" + ie_height.ToString();
Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
// sliderOneDay.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderOneDay_ValueChanged);
//Me.PlaybackTrackChanged += new EventHandler<Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs>(Me_PlaybackTrackChanged);
}
//全屏原理
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interop;
using System.Windows.Browser;
using System.Collections.Generic;
namespace SilverlightApplication5
{
public partial class MainPage : UserControl
{
private static bool _isNavigator;
public string PlayUri = string.Empty;
public double player_width = 480; //播放器宽
public double player_height = 360; //播放器高
public double ie_width = 1366;// (double)Screen.GetProperty("width");
public double ie_height = 768;// (double)Screen.GetProperty("height");
//public double ie_width = App.Current.Host.Content.ActualWidth; //容器宽
//public double ie_height = App.Current.Host.Content.ActualHeight; //容器高
private static ScriptObject Screen
{
get
{
ScriptObject screen = (ScriptObject)HtmlPage.Window.GetProperty("screen");
if (screen == null)
{
throw new InvalidOperationException();
} return screen;
}
}
public MainPage(IDictionary<string, string> dicParam)
{
InitializeComponent();//该句应该放在该函数里第一行,否则报错
_isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape");
//dicParam.TryGetValue("broadcastUrl", out PlayUri);
Me.SmoothStreamingSource = new Uri(App.mediaurl);
label1.Content = PlayUri.ToString();
// 为初始化变量所必需
C.Width = player_width;
C.Height = player_height + 40;
Me.Width = player_width;
Me.Height = player_height;
StackControl.Width = player_width;
label1.Content = ie_width.ToString() + ":" + ie_height.ToString();
Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
// sliderOneDay.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderOneDay_ValueChanged);
//Me.PlaybackTrackChanged += new EventHandler<Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs>(Me_PlaybackTrackChanged);
}
public MainPage()
{
//_isNavigator = HtmlPage.BrowserInformation.Name.Contains("Netscape");
//// 为初始化变量所必需
InitializeComponent();
//C.Width = player_width;
//C.Height = player_height + 40;
//Me.Width = player_width;
//Me.Height = player_height;
//StackControl.Width = player_width;
//label1.Content = ie_width.ToString() + ":" + ie_height.ToString();
//Application.Current.Host.Content.FullScreenChanged += new EventHandler(Content_FullScreenChanged);
// sliderOneDay.ValueChanged += new RoutedPropertyChangedEventHandler<double>(sliderOneDay_ValueChanged);
//Me.PlaybackTrackChanged += new EventHandler<Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs>(Me_PlaybackTrackChanged);
}
void sliderOneDay_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
Me.Position = new TimeSpan(0, 0, 10);
//Me.LivePlaybackStartPosition = Microsoft.Web.Media.SmoothStreaming.PlaybackStartPosition.Beginning;
}
void Me_PlaybackTrackChanged(object sender, Microsoft.Web.Media.SmoothStreaming.TrackChangedEventArgs e)
{
//label1.Content = "播放比特率:" + Me.DownloadProgress.ToString();
}
private void FsBtn_Click(object sender, RoutedEventArgs e)
{
Content contentObject = Application.Current.Host.Content;
contentObject.IsFullScreen = !contentObject.IsFullScreen;
}
private void Content_FullScreenChanged(object sender, EventArgs e)
{
bool isfull = Application.Current.Host.Content.IsFullScreen;
if (isfull)
{
Me.Width = ie_width;
Me.Height = ie_height - 40;
label1.Content = "全屏了:" + Me.Width.ToString() + ":" + Me.Height.ToString();
this.Width = ie_width;
this.Height = ie_height;
this.C.Width = ie_width;
this.C.Height = ie_height;
//全屏模式下如果光标移动到客户浏览器下面边栏可以显示出播放器的控制栏
//label1.Content = StackControl.Margin.Left.ToString() + ":" + StackControl.Margin.Top.ToString() + ":" + StackControl.Margin.Right.ToString() + ":" + StackControl.Margin.Bottom.ToString();
StackControl.MouseEnter += delegate(object s, MouseEventArgs ev)
{
StackControl.Opacity = 1;
};
StackControl.MouseLeave += delegate(object s, MouseEventArgs ev)
{
StackControl.Opacity = 0;
};
}
else
{
StackControl.Opacity = 1;
label1.Content = Me.Width.ToString() + ":" + Me.ActualWidth.ToString();
StackControl.MouseEnter += delegate(object s, MouseEventArgs ev)
{
StackControl.Opacity = 1;
};
StackControl.MouseLeave += delegate(object s, MouseEventArgs ev)
{
StackControl.Opacity = 1;
};
Me.Width = player_width;
Me.Height = player_height;
this.Width = player_width;
this.Height = player_height + 40;
this.C.Width = player_width;
this.C.Height = player_height + 40;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Me.Stop();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
Me.Stop();
Me.Play();
}
public static double ClientWidth
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerWidth")
: (double)HtmlPage.Document.Body.GetProperty("clientWidth");
}
}
/// <summary>
/// Gets the window object's client height
/// </summary>
public static double ClientHeight
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("innerHeight")
: (double)HtmlPage.Document.Body.GetProperty("clientHeight");
}
}
/// <summary>
/// Gets the current horizontal scrolling offset
/// </summary>
public static double ScrollLeft
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageXOffset")
: (double)HtmlPage.Document.Body.GetProperty("scrollLeft");
}
}
/// <summary>
/// Gets the current vertical scrolling offset
/// </summary>
public static double ScrollTop
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("pageYOffset")
: (double)HtmlPage.Document.Body.GetProperty("scrollHeight");
}
}
/// <summary>
/// Gets the width of the entire display
/// </summary>
public static double ScreenWidth
{
get
{
return (double)Screen.GetProperty("width");
}
}
/// <summary>
/// Gets the height of the entire display
/// </summary>
public static double ScreenHeight
{
get
{
return (double)Screen.GetProperty("height");
}
}
/// <summary>
/// Gets the width of the available screen real estate, excluding the dock
/// or task bar
/// </summary>
public static double AvailableScreenWidth
{
get
{
return (double)Screen.GetProperty("availWidth");
}
}
/// <summary>
/// Gets the height of the available screen real estate, excluding the dock /// or task bar
/// </summary>
public static double AvailableScreenHeight
{
get
{
return (double)Screen.GetProperty("availHeight");
}
}
/// <summary>
/// Gets the absolute left pixel position of the window in display coordinates
/// </summary>
public static double ScreenPositionLeft
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenX")
: (double)HtmlPage.Window.GetProperty("screenLeft");
}
}
/// <summary>
/// Gets the absolute top pixel position of the window in display coordinates
/// </summary>
public static double ScreenPositionTop
{
get
{
return _isNavigator ? (double)HtmlPage.Window.GetProperty("screenY")
: (double)HtmlPage.Window.GetProperty("screenTop");
}
}
}
}
浙公网安备 33010602011771号