一个silverlight播放器的DEMO(Expression Encoder 2)

本文介绍如何使用ExpressionEncoder创建自定义播放列表,通过修改XAML和JS文件实现媒体文件的点播功能,包括添加导航箭头、播放按钮及相应事件处理。
    因为这个DEMO的演示用到了Expression Encoder, 而相关下载链接, 请点击这里。      

     原文中的老外因为不满足于Expression Encoder所提供的模板代码,他认为在媒体列表中应该实现点播的效果。而
不仅仅是“一味”的顺序播放。因此他在Expression Encoder代码生成的基础上,对Xaml和js文件都做了相应改动。下面
我们来看一下他所开发的主要流程。


     首先使用Expression Encoder来创建一个项目,并将其模板设置为"Expression" (因为本人不喜欢这个模板,所以在DEMO中使用了"Executive"模板),然后单击Import按钮来选择要播放的视频文件。如下图所示。最后单击“Encode”进行编码转换(当转换成功后会启动一个测试页面进行演示,“Preview In Brower”需勾选)。



     这样我们就可以在“Directory”设置项中下找到我们所生成的所有项目文件了。

    因为模板文件生成的XAML中不带播放列表,所以要修改XAML文件中
 Canvas 的高度,并将下面的XAML代码(播入列表代码)放在该文件的结尾处:

<!--  Playlist region starts here  -->
<!--  Navigation Arrows   -->
< Path  x:Name ="LeftArrow"  Opacity ="0.74"  Width ="38"  Height ="38"  Stretch ="Fill"  Stroke ="#FF000000"  
Canvas.Left
="11"  Canvas.Top ="514"  Data ="M37.5,0.5 L37.5,37.5 0.5,37.5 z"  Fill ="#FFFFFFFF"  
RenderTransformOrigin
="0.5,0.5"  Cursor ="Hand" >
    
< Path.RenderTransform >
        
< TransformGroup >
            
< ScaleTransform  ScaleX ="1"  ScaleY ="1" />
            
< SkewTransform  AngleX ="0"  AngleY ="0" />
            
< RotateTransform  Angle ="134.119" />
            
< TranslateTransform  X ="0"  Y ="0" />
        
</ TransformGroup >
    
</ Path.RenderTransform >
</ Path >
< Path  x:Name ="RightArrow"  Opacity ="0.74"  Width ="38"  Height ="38"  Stretch ="Fill"  Stroke ="#FF000000"  
Canvas.Left
="588"  Canvas.Top ="514"  Data ="M37.5,0.5 L37.5,37.5 0.5,37.5 z"  Fill ="#FFFFFFFF"  
RenderTransformOrigin
="0.5,0.5"  Cursor ="Hand" >
    
< Path.RenderTransform >
        
< TransformGroup >
            
< ScaleTransform  ScaleX ="1"  ScaleY ="1" />
            
< SkewTransform  AngleX ="0"  AngleY ="0" />
            
< RotateTransform  Angle ="314.365" />
            
< TranslateTransform  X ="0"  Y ="0" />
        
</ TransformGroup >
    
</ Path.RenderTransform >
</ Path >

<!--  The outer canvas here is clipped: only the area defined by the rectangle geometry is visible   -->
<!--  This is necessary as when we animate the 'Library' canvas inside it we do not want to see the 
thumbnails slide under the navigation arrows and off the screen
-->
< Canvas  x:Name ="ClippedCanvas"  Canvas.Top ="491"  Canvas.Left ="43"  Width ="550"  Height ="90"  
Background
="Silver" >
    
< Canvas.Clip >
        
< RectangleGeometry  Rect ="0, 0, 550, 114" />
    
</ Canvas.Clip >
   
    
<!--  Animations to move the playlist left and right. They are numbered so that we can call them 
logically from code 
-->
    
< Canvas.Resources >
        
< Storyboard  x:Name ="MoveLeft01" >
            
< DoubleAnimation  Storyboard.TargetProperty ="(Canvas.Left)"  Storyboard.TargetName ="Library"  
                                   From ="13"  To ="-613"  Duration ="0:0:2"   />
        
</ Storyboard >
        
< Storyboard  x:Name ="MoveRight02" >
            
< DoubleAnimation  Storyboard.TargetProperty ="(Canvas.Left)"  Storyboard.TargetName ="Library"  
                                   From ="-613"  To ="13"  Duration ="0:0:2"   />
        
</ Storyboard >
    
</ Canvas.Resources >
   
    
<!--  The Library Canvas groups the playlist buttons into a single element that can be easily animated 
left - right.  
-->        
    
< Canvas  Width ="1157.275"  Height ="82.96"  Canvas.Left ="0"  Canvas.Top ="0"  x:Name ="Library" >
        
< Canvas  Width ="550.275"  Height ="82.96"  x:Name ="playlist1" >
            
< Image  x:Name ="play0"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="1.png"  
                                   Stretch ="Fill"  Cursor ="Hand"   />
            
< Image  x:Name ="play1"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="2.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="139" />
            
< Image  x:Name ="play2"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="3.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="278" />
            
< Image  x:Name ="play3"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="4.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="417" />
        
</ Canvas >
        
< Canvas  Width ="550.275"  Height ="82.96"  x:Name ="playlist2"  Canvas.Left ="607" >
            
< Image  x:Name ="play4"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="5.png"  
                                   Stretch ="Fill"  Cursor ="Hand"   />
            
< Image  x:Name ="play5"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="6.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="139" />
            
< Image  x:Name ="play6"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="7.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="278" />
            
< Image  x:Name ="play7"  Opacity ="0.74"  Width ="133.275"  Height ="82.96"  Source ="8.png"  
                                   Stretch ="Fill"  Cursor ="Hand"  Canvas.Left ="417" />
        
</ Canvas >
    
</ Canvas >
</ Canvas >

    
    下面就要改一下相应的js文件了,找到StartPlayer.js文件,新的播入列表方法放在页面的最上面:

// 全局变量声明

var  curPos  =   1 // 当前播入的媒体文件在列表中的位置
var  maxPos  =   2 // 当前的分页数,因为是8个文件,每4个文件为1页,所以这里是两页
var  cVideos  =   8 // 视频文件个数(本DEMO中有8个)

function  get_mediainfo(mediainfoIndex) {
    
switch  (mediainfoIndex) {       

        
case   0 :
            
return   {  " mediaSource " " Movie1.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   1 :
            
return   {  " mediaSource " " Movie2.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   2 :
            
return   {  " mediaSource " " Movie3.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   3 :
            
return   {  " mediaSource " " Movie4.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   4 :
            
return   {  " mediaSource " " Movie5.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   5 :
            
return   {  " mediaSource " " Movie6.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   6 :
            
return   {  " mediaSource " " Movie7.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               

        
case   7 :
            
return   {  " mediaSource " " Movie8.wmv " ,
                      
" placeholderSource " "" ,
                      
" chapters " : [] };                                                               
                         
        
default :
             
throw  Error.invalidOperation( " No such mediainfo " );
     }
}

   将原码中的原有播放文件列表变量和相关内容注释:

//     this._playlist=[];
//
    try {
//
        eval( 'this._playlist=['+
//
        '{"mediaSource":"15_mt_l2s_callingsqlfunctions.wmv",'+
//
        '"placeholderSource":"",'+
//
        '"chapters":'+
//
            '['+
//
            ']},'+
//
        '{"mediaSource":"18_mt_l2s_transactions.wmv",'+
//
        '"placeholderSource":"",'+
//
        '"chapters":'+
//
            '['+
//
            ']}'+
//
        '];' );
//
    }
//
    catch(e){}

//     this._galleryItems=[];
//
    try {
//
        eval( 'this._galleryItems=['+
//
        'new ExpressionPlayer.GalleryItem("15_mt_l2s_callingsqlfunctions.wmv",""),'+
//
        'new ExpressionPlayer.GalleryItem("18_mt_l2s_transactions.wmv","")'+
//
        '];' );
//
    }
//
    catch(e){}

//     this._player.set_galleryInfo( this._galleryItems, Function.createDelegate(this, this._onClickGalleryItem) ); 
//
    this._onPlayNextVideo(null,null);   

      将下列代码放在该注释下方来解决对相应媒体播放按钮进行事件绑定:

// wire up the rollover and click events for each of our play buttons       

this .Plugin  =  document.getElementById( this ._hostname);

for  ( var  i  =   0 ; i  <  cVideos; i ++ )
{
    
var  element  =   this .Plugin.Content.findName( ' play '   +  i);
    element.addEventListener(
" MouseEnter " , Function.createDelegate( this , this ._rollOver));
    element.addEventListener(
" MouseLeave " , Function.createDelegate( this , this ._rollOut));
    element.addEventListener(
" MouseLeftButtonUp " , Function.createDelegate( this , this ._playX));
}

this .Plugin.Content.findName( ' LeftArrow ' ).addEventListener( " MouseEnter "
                                   Function.createDelegate( this , this ._rollOver));
this .Plugin.Content.findName( ' LeftArrow ' ).addEventListener( " MouseLeave "
                                   Function.createDelegate( this , this ._rollOut));
this .Plugin.Content.findName( ' LeftArrow ' ).addEventListener( " MouseLeftButtonUp "
                                   Function.createDelegate( this , this ._slideLeft));
this .Plugin.Content.findName( ' RightArrow ' ).addEventListener( " MouseEnter "
                                   Function.createDelegate( this , this ._rollOver));
this .Plugin.Content.findName( ' RightArrow ' ).addEventListener( " MouseLeave "
                                   Function.createDelegate( this , this ._rollOut));
this .Plugin.Content.findName( ' RightArrow ' ).addEventListener( " MouseLeftButtonUp "
                                  Function.createDelegate(
this , this ._slideRight));

this ._onPlayNextVideo( null null );    


    而下面就是其相应的事件处理代码了:

  

 _rollOver:  function (sender, eventArgs) {
    sender.opacity
= 1 ;
 },
 
  _rollOut: 
function (sender, eventArgs) {
    sender.opacity
= 0.74 ;
 },
 
 _playX: 
function (sender, eventArgs) {
    
var  X  =  Number(sender.Name.substring( 4 ));
    
this ._currentMediainfo  =  X;
    
this ._player.set_mediainfo( get_mediainfo( X ));
    sender.opacity
= 1 ;
 },
 
 _slideLeft: 
function (sender, eventArgs) {
      
switch (curPos)
      {
          
case   1 :
              sender.findName(
" LeftArrow " ).opacity  =   0.85 ;
              
break ;
          
default :
              sender.findName(
" MoveRight0 "   +  curPos).Begin();
              curPos
-- ;  
      }
 }, 
 
 _slideRight: 
function (sender, eventArgs) {
    
switch (curPos)
      {              
          
case  maxPos:
              sender.findName(
" RightArrow " ).opacity  =   0.85
            
break ;               
          
default :
            sender.findName(
" MoveLeft0 "   +  curPos).Begin();
              curPos
++ ;
              sender.findName(
" LeftArrow " ).opacity  =   1 ;     
      }
 }


     因为使用了新的播放列表变量,所以原来生成的如下方法内容会被改写如下:
  

_onPlayPreviousVideo:  function (sender, eventArgs) {
    
if  ( this ._currentMediainfo > 0 )      
    {
        
this ._player.set_mediainfo(get_mediainfo( -- this ._currentMediainfo ));   
    }  
},

_onPlayNextVideo: 
function (sender, eventArgs) {
    
if  ( this ._currentMediainfo < cVideos)      
    {
        
this ._player.set_mediainfo(get_mediainfo( ++ this ._currentMediainfo ));   
    }
},
 

     到这里我们可以在本地运行一下default.htm来看一下效果。

     然后为了演示方便,我将这个Application上传到了Silverlight Streaming
上,经常了n遍的上传之后,终于测试成功,所以才在本文开头做了相应的演示。

    好了,今天的内容就先到这里了.



本文转自 daizhenjun 51CTO博客,原文链接:http://blog.51cto.com/daizhj/86909,如需转载请自行联系原作者

内容概要:本文详细介绍了一个基于MATLAB实现的SWT-SVM故障诊断分类预测项目,通过平稳小波变换(SWT)进行信号去噪与多尺度特征提取,结合支持向量机(SVM)实现机械设备故障的智能分类。项目涵盖从数据采集、预处理、SWT分解、特征提取与降维(如PCA)、模型训练与优化(含交叉验证、网格搜索、贝叶斯优化)、性能评估(混淆矩阵、ROC曲线、F1分数等)到结果可视化与GUI界面开发的完整流程。系统具备高可解释性、强鲁棒性和良好工程集成能力,适用于多行业设备健康监测,并提供完整的代码实现与部署方案。; 适合人群:具备一定MATLAB编程基础,熟悉信号处理与机器学习算法的高校研究生、科研人员及工业领域从事设备故障诊断、智能运维的工程师和技术人员。; 使用场景及目标:①应用于智能制造、风电、轨道交通、石化、航空航天等领域的设备故障早期检测与健康状态评估;②构建端到端的智能诊断pipeline,提升诊断准确率与自动化水平;③通过GUI交互界面实现数据导入、模型训练、实时预测与结果导出,服务于科研教学与工业实际部署。; 阅读建议:建议读者结合文中提供的完整MATLAB代码与GUI设计,逐步复现各模块功能,重点关注SWT参数选择、特征降维策略、SVM超参数优化及模型评估方法。在实践过程中调试信号处理流程与分类性能,深入理解算法原理与工程落地的关键环节。
【Copula光伏功率预测】基于单调广义学习系统(MBLS)和Copula理论的时空概率预测模型(Matlab代码实现)内容概要:本文介绍了一个基于单调广义学习系统(MBLS)和Copula理论的时空概率预测模型,用于光伏功率预测,并提供了Matlab代码实现。该模型结合了MBLS在函数逼近和学习能力方面的优势,以及Copula理论在处理多变量非高斯分布和捕捉变量间复杂相关性结构的能力,能够有效处理光伏出力的不确定性与时空相关性,从而提高预测精度和可靠性。此外,文档还列举了多个相关的科研方向和技术应用实例,如风电预测、虚拟电厂调度、风光制氢合成氨系统优化、多目标优化算法等,展示了其在电力系统、新能源、优化调度等多个领域的广泛应用前景。; 适合人群:具备一定编程基础,尤其是熟悉Matlab编程语言,从事新能源、电力系统、优化调度、机器学习等相关领域研究的科研人员和研究生。; 使用场景及目标:①应用于光伏发电功率的高精度时空概率预测,为电网调度、能源管理和市场交易提供决策支持;②作为研究Copula理论和MBLS算法在复杂非线性系统建模中应用的案例,促进相关算法的改进与创新;③结合文中提到的其他优化算法(如多目标优化、智能优化算法)和应用场景(如虚拟电厂、综合能源系统),构建更复杂的系统优化与决策模型。; 阅读建议:此资源不仅提供了具体的代码实现,还涵盖了丰富的科研背景和应用方向。建议读者在学习过程中,不仅要理解MBLS和Copula理论的核心思想与实现细节,还应结合文中提及的其他技术(如优化算法、深度学习模型)进行横向对比和综合应用,以拓宽研究视野。同时,鼓励读者基于提供的代码框架,针对具体问题进行参数调整和模型改进,通过实践加深对理论的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值