一。后台拼字符串动态加载写法
前台调用代码
后台调用代码
protected void Page_Load(object sender, EventArgs e)
{
this.video_content.InnerHtml = PlayMedia.Play("http://hot.tudou.com/flv/005/680/205/5680205.flv", 472,385);
}
视频播放类:
using System;
using System.Collections.Generic;
using System.Text;
namespace Common
{
public class PlayMedia
{
public PlayMedia()
{
//
// TOD 在此处添加构造函数逻辑
//
}
public static string Play(string url, int width, int height)
{
string strTmp = url.ToLower();
if (strTmp.EndsWith(".wmv") || strTmp.EndsWith(".mp3") || strTmp.EndsWith(".wma") || strTmp.EndsWith(".avi") || strTmp.EndsWith(".asf") || strTmp.EndsWith(".mpg"))
{
return wmv(url, width, height);
}
else if (strTmp.EndsWith(".mp3"))
{
return mp3(url, width, height);
}
else if (strTmp.EndsWith(".swf"))
{
return swf(url, width, height);
}
else if (strTmp.EndsWith(".flv"))
{
return flv(url, width, height);
}
else if (strTmp.EndsWith(".jpg") || strTmp.EndsWith(".gif"))
{
return img(url, width, height);
}
else if (strTmp.EndsWith(".rm"))
{
return rm(url, width, height);
}
else
{
return "视频文件数据错误";
}
}
///
/// flv格式文件播放
///
///
///
private static string flv(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
return sb.ToString();
}
///
/// wmv格式文件播放
///
///
///
private static string wmv(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("
\n");
return sb.ToString();
}
private static string wma(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("
sb.Append("");
return sb.ToString();
}
///
/// avi格式文件播放
///
///
///
private static string avi(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
return sb.ToString();
}
private static string mpg(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
return sb.ToString();
}
private static string rm(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
return sb.ToString();
}
private static string swf(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
return sb.ToString();
}
private static string mp3(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
sb.Append("");
return sb.ToString();
}
private static string img(string url, int width, int height)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("");
return sb.ToString();
}
}
}
二。前台拼字符串JS调用写法
FLV需要播放器,其它视频格式直接插入相应的代码即可。 ------------------------------------- /** *参数说明 u - 媒体URL w - 媒体宽度width h - 媒体高度height */ //播放Mediaplayer格式的视频,包括.avi .mpg .mpeg .wmv .wma .asf .mid .mp3等 function pv_m(u, w, h){ var pv=''; pv += ''; document.write(pv); } //播放Realplay格式的视频,包括.rm .ram .rmvb等 function pv_r(u, w, h){ var pv=''; pv += ''; document.write(pv); } //播放Quicktime格式的视频,包括.mov .amr .3gp等 function pv_q(u, w, h){ var pv=''; pv += ''; document.write(pv); }