用Media Player 播放 mpg檔案

huanghuang發表於2006-10-24
先說明的是此mpg檔案,如果不安裝一個Media Player Filter包,Media Player 是不能播放的,所以在每臺機器上都安裝了Media Player Filter包。

1.頁面上播放mpg檔案,如果向下面這樣,能正常播放,(filename 引數直接寫檔名稱<param name="Filename" value="d://clip.mpg">)


<object classid=CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95
id=NSPlay type=application/x-oleobject width="390" height="390">
<param name="AudioStream" value="-1">
<param name="AutoSize" value="0">
<param name="AutoStart" value="-1">
<param name="AnimationAtStart" value="-1">
<param name="AllowScan" value="-1">
<param name="AllowChangeDisplaySize" value="-1">
<param name="AutoRewind" value="0">
<param name="Balance" value="0">
<param name="BaseURL" value>
<param name="BufferingTime" value="5">
<param name="CaptioningID" value>
<param name="ClickToPlay" value="-1">
<param name="CursorType" value="0">
<param name="CurrentPosition" value="-1">
<param name="CurrentMarker" value="0">
<param name="DefaultFrame" value>
<param name="DisplayBackColor" value="0">
<param name="DisplayForeColor" value="16777215">
<param name="DisplayMode" value="0">
<param name="DisplaySize" value="2">
<param name="Enabled" value="-1">
<param name="EnableContextMenu" value="-1">
<param name="EnablePositionControls" value="-1">
<param name="EnableFullScreenControls" value="0">
<param name="EnableTracker" value="-1">
<param name="InvokeURLs" value="-1">
<param name="Language" value="-1">
<param name="Mute" value="0">
<param name="PlayCount" value="1">
<param name="PreviewMode" value="0">
<param name="Rate" value="1">
<param name="SAMILang" value>
<param name="SAMIStyle" value>
<param name="SAMIFileName" value>
<param name="SelectionStart" value="-1">
<param name="SelectionEnd" value="-1">
<param name="SendOpenStateChangeEvents" value="-1">
<param name="SendWarningEvents" value="-1">
<param name="SendErrorEvents" value="-1">
<param name="SendKeyboardEvents" value="0">
<param name="SendMouseClickEvents" value="0">
<param name="SendMouseMoveEvents" value="0">
<param name="SendPlayStateChangeEvents" value="-1">
<param name="ShowCaptioning" value="0">
<param name="ShowControls" value="-1">
<param name="ShowAudioControls" value="-1">
<param name="ShowDisplay" value="0">
<param name="ShowGotoBar" value="0">
<param name="ShowPositionControls" value="-1">
<param name="ShowStatusBar" value="-1">
<param name="ShowTracker" value="-1">
<param name="TransparentAtStart" value="0">
<param name="VideoBorderWidth" value="0">
<param name="VideoBorderColor" value="0">
<param name="VideoBorder3D" value="0">
<param name="Volume" value="-40">
<param name="WindowlessVideo" value="0">
<param name="Filename" value="d://clip.mpg">

<!--
value="</%=basePath%>servlet/imageViewer?key=21">
-->
</object>
2.如果向下面這樣,不能正常播放,(filename 引數直接寫檔名稱<param name="Filename" value="http://127.0.0.1:8080/dzgl/show/test.jsp?key=1&from=1">)

<object classid=CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95
id=NSPlay type=application/x-oleobject width="390" height="390">
<param name="AudioStream" value="-1">
<param name="AutoSize" value="0">
<param name="AutoStart" value="-1">
<param name="AnimationAtStart" value="-1">
<param name="AllowScan" value="-1">
<param name="AllowChangeDisplaySize" value="-1">
<param name="AutoRewind" value="0">
<param name="Balance" value="0">
<param name="BaseURL" value>
<param name="BufferingTime" value="5">
<param name="CaptioningID" value>
<param name="ClickToPlay" value="-1">
<param name="CursorType" value="0">
<param name="CurrentPosition" value="-1">
<param name="CurrentMarker" value="0">
<param name="DefaultFrame" value>
<param name="DisplayBackColor" value="0">
<param name="DisplayForeColor" value="16777215">
<param name="DisplayMode" value="0">
<param name="DisplaySize" value="2">
<param name="Enabled" value="-1">
<param name="EnableContextMenu" value="-1">
<param name="EnablePositionControls" value="-1">
<param name="EnableFullScreenControls" value="0">
<param name="EnableTracker" value="-1">
<param name="InvokeURLs" value="-1">
<param name="Language" value="-1">
<param name="Mute" value="0">
<param name="PlayCount" value="1">
<param name="PreviewMode" value="0">
<param name="Rate" value="1">
<param name="SAMILang" value>
<param name="SAMIStyle" value>
<param name="SAMIFileName" value>
<param name="SelectionStart" value="-1">
<param name="SelectionEnd" value="-1">
<param name="SendOpenStateChangeEvents" value="-1">
<param name="SendWarningEvents" value="-1">
<param name="SendErrorEvents" value="-1">
<param name="SendKeyboardEvents" value="0">
<param name="SendMouseClickEvents" value="0">
<param name="SendMouseMoveEvents" value="0">
<param name="SendPlayStateChangeEvents" value="-1">
<param name="ShowCaptioning" value="0">
<param name="ShowControls" value="-1">
<param name="ShowAudioControls" value="-1">
<param name="ShowDisplay" value="0">
<param name="ShowGotoBar" value="0">
<param name="ShowPositionControls" value="-1">
<param name="ShowStatusBar" value="-1">
<param name="ShowTracker" value="-1">
<param name="TransparentAtStart" value="0">
<param name="VideoBorderWidth" value="0">
<param name="VideoBorderColor" value="0">
<param name="VideoBorder3D" value="0">
<param name="Volume" value="-40">
<param name="WindowlessVideo" value="0">
<param name="Filename" value="http://127.0.0.1:8080/dzgl/show/test.jsp?key=1&from=1">

<!--
value="</%=basePath%>servlet/imageViewer?key=21">
-->
</object>
/show/test.jsp 如下:


<%@ page language="java"%>
<%@ page import="java.io.*"%>

<%
response.setContentType("bin");

int maxBufferLength = 81920;
byte[] b = new byte[maxBufferLength];
InputStream fs = new FileInputStream("d://Clip.mpg"); // 不能正常播放
//InputStream fs = new FileInputStream("d://speedis.avi");
// b = new byte[fs.available()];
b = new byte[maxBufferLength];
DataOutputStream outTmp = new DataOutputStream(response.getOutputStream());
int len;
try {

if (fs != null) {
while ((len = fs.read(b)) > 0) {
outTmp.write(b, 0, len); //這出的錯
}
} catch (Exception e) {
e.printStackTrace();

}

}finally{
outTmp.close();
}

%>
第2種方法出現的異常是:
ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
問: 我要的是第2種方法,因為需要從資料庫中讀出檔案內容。不知道第2種方法為什麼不正常播放。

相關文章