实现带列表的视频播放2

在ASP.NET网站中实现带列表的视频播放

方法:
用c#将视频文件上传到磁盘上时同时生产对应的xml文件,播放页面使用js读取对应的xml文件生成播放列表。
xml文件:
文件名:huojian.xml

视频上传代码:

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

using  System.Xml;
public   partial   class  _Default : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (User.Identity.Name != @"banewfish/banewfish")
        
{
            Label1.Text 
= "您当前不具有当前网页的使用权限!<br/>如需上传文件请于管理员联系!";
            
try
            
{
                FileUpload1.Enabled 
= false;
                Button1.Enabled 
= false;
            }

            
catch (Exception exDisenabledContorls)
            
{
                FileUpload1.Enabled 
= false;
                Button1.Enabled 
= false;
               
            }

            
finally
            
{
                FileUpload1.Enabled 
= false;
                Button1.Enabled 
= false;
            }

           
        }
 

    }

    
private string path;
    
protected void Button1_Click(object sender, EventArgs e)
    
{
        
string xmlDocName = dl.SelectedValue;
        
if (Page.IsPostBack)
        
{
            Label1.Text 
= "";
            Boolean fileOK 
= false;
            
if (FileUpload1.HasFile)
            
{
                String fileExtension 
=
                    System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
                String[] allowedExtensions 
= ".wmv"".mpg"".mpeg" };
                
for (int i = 0; i < allowedExtensions.Length; i++)
                
{
                    
if (fileExtension == allowedExtensions[i])
                    
{
                        fileOK 
= true;
                    }

                }

            }

            
else Label1.Text = "文件名不能为空";
            
if (fileOK)
            
{

                path 
= Server.MapPath("~/UploadedImages/");
                
try
                
{
                    FileUpload1.PostedFile.SaveAs(path 
+ FileUpload1.FileName);
                }

                
catch (Exception exSaveFile)
                
{
                    fileOK 
= false;
                    Label1.Text 
= "文件存储到服务器时出错,可能是文件已损坏或文件为空+" + exSaveFile.ToString();
                }

                
//object[] pa = new object[] { FileUpload1.FileName.ToLower(),12, Page.User.Identity.Name.ToString() };
                
//Label1.Text += InsertToDataBase(@"Data Source=s-sql;Initial Catalog=sps;Integrated Security=True", pa);
                if (fileOK)
                
{
                    Label1.Text 
+= InsertToXML(xmlDocName);
                }

            }

            
else
            
{
                Label1.Text 
= "文件类型错误,允许的文件类型为: wmv、mpg、mpeg";
            }

        }


        
//Page.Response.Write(file1.value);
    }

    
private string InsertToXML(string xmlDocName)
    
{
        XmlDocument xmlDoc 
= new XmlDocument();
        
string fileName = xmlDocName + ".xml";
        
try
        
{

            xmlDoc.Load(Page.MapPath(fileName));
        }

        
catch (Exception exLoadxml)
        
{
            
return xmlDocName;
        }


        XmlNode root 
= xmlDoc.SelectSingleNode("media");//查找<media>
        XmlElement xe1 = xmlDoc.CreateElement("pp");//创建一个<pp>节点
        xe1.SetAttribute("url","http://s-sps:801/UploadedImages/"+FileUpload1.FileName.ToLower());//设置该节点url属性
        xe1.SetAttribute("name", FileUpload1.FileName.ToLower().Remove(FileUpload1.FileName.ToLower().LastIndexOf(".")));//设置该节点name属性
        root.AppendChild(xe1);//添加到<bookstore>节点中
        xmlDoc.PreserveWhitespace = true;
        xmlDoc.Save(Page.MapPath(fileName));
        
return "上传成功";
    }

}


视频播放模块代码:
< table cellspacing = " 0 "  cellpadding = " 4 "  width = " 100% "  border = " 0 " >
        
< tbody >
            
< tr >
                
< td style = " vertical-align: top; width: 70% " >
                    
< object  id = " pl "  style = " width: 100%; height: 519px "  classid = " clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6 "
                        viewastext
= "" >
                        
< param value = ""  name = " URL "   />
                        
< param value = " 1 "  name = " rate "   />
                        
< param value = " 0 "  name = " balance "   />
                        
< param value = " 0 "  name = " currentPosition "   />
                        
< param value = ""  name = " defaultFrame "   />
                        
< param value = " 1 "  name = " playCount "   />
                        
< param value = " -1 "  name = " autoStart "   />
                        
< param value = " 0 "  name = " currentMarker "   />
                        
< param value = " -1 "  name = " invokeURLs "   />
                        
< param value = ""  name = " baseURL "   />
                        
< param value = " 50 "  name = " volume "   />
                        
< param value = " 0 "  name = " mute "   />
                        
< param value = " full "  name = " uiMode "   />
                        
< param value = " 0 "  name = " stretchToFit "   />
                        
< param value = " 0 "  name = " windowlessVideo "   />
                        
< param value = " -1 "  name = " enabled "   />
                        
< param value = " -1 "  name = " enableContextMenu "   />
                        
< param value = " 0 "  name = " fullScreen "   />
                        
< param value = ""  name = " SAMIStyle "   />
                        
< param value = ""  name = " SAMILang "   />
                        
< param value = ""  name = " SAMIFilename "   />
                        
< param value = ""  name = " captioningID "   />
                        
< param value = " 0 "  name = " enableErrorDialogs "   />
                        
< param value = " 6482 "  name = " _cx "   />
                        
< param value = " 6350 "  name = " _cy "   />
                    
</ object >
                
</ td >
                
< td style = " vertical-align: top; width: 30% " >
                    播放列表
< br  />

                    
< script language = " javascript "  type = " text/javascript " >                      
                     
//  JScript 文件                
                     function loadXML(xmlFile)                    
                     
{                        
                         var xmlDoc;                        
                         
if(window.ActiveXObject)                        
                         
{                            
                             xmlDoc    
= new ActiveXObject('Microsoft.XMLDOM');                            
                             xmlDoc.async    
= false;                            
                             xmlDoc.load(xmlFile);                        
                         }
                        
                         
else if (document.implementation&&document.implementation.createDocument)
                         
{                            
                             xmlDoc    
= document.implementation.createDocument(''''null);                            
                             xmlDoc.load(xmlFile);                        
                         }
                        
                         
else                        
                         
{                            
                            
return null;                        
                         }
                                                
                     
return xmlDoc;                    
                     }
                   
                      
// 一个检查xml文件的函数                    
                      checkXMLDocObj  =  function(xmlFile)                    
                      
{                        
                          var xmlDoc    
= loadXML(xmlFile);                        
                          
if(xmlDoc==null)                        
                          
{                            
                              alert(
'您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!');
                              window.location.href
='/Index.aspx';                        
                          }
                        
                          
return xmlDoc;                    
                      }
                
                      function doo()                 
                      
{                     
                          
// 定义一个读取xml文件的对象                     
                          var xmlDoc    = checkXMLDocObj('http://s-sps:801/huojian.xml');                     
                          var name 
= new Array();                     
                          var url 
= new Array();                     
                          var sum
=xmlDoc.getElementsByTagName("pp").length;                     
                          
for(var i=0; i<sum; i++)                     
                          
{                          
                              url[i]
=xmlDoc.getElementsByTagName('media/pp')[i].getAttribute('url');                          
                              name[i]
=xmlDoc.getElementsByTagName('media/pp')[i].getAttribute('name');
                          }
                     
                          var str 
= new Array();                     
                          
for(var i=0; i<sum; i++)                     
                          
{                        
                              str[i]
="return play('"+url[i]+"')";                     
                          }
                     
                          document.write(
'<table border="0" cellpadding="0" cellspacing="0">');                     
                          
for(var i=0; i<sum; i++)                     
                          
{                         
                              var x 
= i+1;                         
                              document.write(
'<tr><td style="background-image: url(playbj.GIF);background-position:center;background-repeat:no-repeat; width:20px;height:24px; text-align:center;vertical-align:middle;" >'+x+'</td><td>');                        
                              document.write(
'<input id=Button1 type=button value='+name[i].toString()+' οnclick="'+str[i]+'" style="padding:2 0 0 2; border:0px;vertical-align:middle; background-color:#fff;text-align:left;">');                         
                              document.write(
'</td></tr>');                         
                              document.write(
'<tr><td style="height:1px;"><td><tr>');                     
                          }
                     
                          document.write(
'</table>');                                 
                     }
                 
                     function play(urlx)                        
                     
{                                                     
                          document.all.item(
"pl").url=urlx;                           
                          document.all.item(
"pl").controls.play();                                                   
                     }
                                    
                      doo();                  
                      
</ script >


                    
                
</ td >
            
</ tr >
            
< tr >
                
< td id = " _invisibleIfEmpty "  style = " display: none "  valign = " top "  width = " 100% "  colspan = " 2 "
                    name
= " _invisibleIfEmpty " >
                
</ td >
            
</ tr >

            
< script language = " javascript " >   if ( typeof (MSOLayout_MakeInvisibleIfEmpty)  ==   " function " {MSOLayout_MakeInvisibleIfEmpty();} </ script >

        
</ tbody >
    
</ table >

<? xml version = " 1.0 "  encoding = " utf-8 "   ?>  
< media >
< pp url = " http://s-sps:801/UploadedImages/badnewfish反坦克导弹.mpeg "  name = " badnewfish反坦克导弹 "   />  
< pp url = " http://s-sps:801/UploadedImages/badnewfish反坦克导弹.mpeg "  name = " badnewfish反坦克导弹 "   />  
</ media >
Android可以通过使用网络请求获取远程视频列表,并实现远程视频播放功能。 首先,需要使用网络请求库(如OkHttp、Volley、Retrofit等)发送请求,获取远程视频列表的数据。可以使用HTTP协议的GET方法发送请求给服务器,服务器返回一个包含视频信息的JSON格式数据。 接下来,需要解析获取到的数据。可以使用JSON解析库(如Gson、JsonSmart等)将JSON数据转化为Java对象,例如一个视频对象包含视频的标题、地址、描述等信息。 一般来说,远程视频播放需要使用特定的视频播放库来实现。在Android系统中,可以使用MediaPlayer类来实现视频播放。创建一个MediaPlayer对象,设置数据源为远程视频的地址,然后调用prepare()方法准备播放,最后调用start()方法开始播放视频。 为了能够展示远程视频列表,可以使用RecyclerView控件展示视频的标题和描述等信息。创建一个RecyclerView对象,设置布局管理器,通常使用LinearLayoutManager或GridLayoutManager来管理RecyclerView的布局。然后创建一个适配器,继承自RecyclerView.Adapter,并在适配器中设置数据源为解析得到的视频列表数据,重写onCreateViewHolder()方法创建ViewHolder实例,再重写onBindViewHolder()方法绑定数据。最后将适配器设置给RecyclerView对象。 当用户点击视频列表中的某个视频时,可以根据视频对象的地址,将其作为数据源设置给MediaPlayer对象,实现远程视频播放播放视频时,还可以为MediaPlayer设置相关的监听器,例如当视频播放完成时,可以设置一个OnCompletionListener监听器,当播放完成时触发相应的操作。 总结起来,实现远程视频播放视频列表功能,需要进行网络请求获取远程视频列表数据,解析数据并展示在RecyclerView中,点击列表项时实现视频播放功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值