這個只要你引用自己背地的MediaPlayer就可以了;代碼:
創(chuàng)新互聯(lián)公司致力于互聯(lián)網(wǎng)品牌建設(shè)與網(wǎng)絡(luò)營銷,包括成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、SEO優(yōu)化、網(wǎng)絡(luò)推廣、整站優(yōu)化營銷策劃推廣、電子商務(wù)、移動互聯(lián)網(wǎng)營銷等。創(chuàng)新互聯(lián)公司為不同類型的客戶提供良好的互聯(lián)網(wǎng)應(yīng)用定制及解決方案,創(chuàng)新互聯(lián)公司核心團(tuán)隊十載專注互聯(lián)網(wǎng)開發(fā),積累了豐富的網(wǎng)站經(jīng)驗,為廣大企業(yè)客戶提供一站式企業(yè)網(wǎng)站建設(shè)服務(wù),在網(wǎng)站建設(shè)行業(yè)內(nèi)樹立了良好口碑。
div id="FlashFile"
object id="player" height="170" width="220"
classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
param NAME="AutoStart" VALUE="1"
!--是否自動播放--
param NAME="Balance" VALUE="0"
!--調(diào)整左右聲道平衡,同上面舊播放器代碼--
param name="enabled" value="-1"
!--播放器是否可人為控制--
param NAME="EnableContextMenu" VALUE="-1"
!--是否啟用上下文菜單--
param NAME="url" value="soft/%=file%"http://源文件路徑
!--播放的文件地址--
param NAME="PlayCount" VALUE="1"
!--播放次數(shù)控制,為整數(shù)--
param name="rate" value="1"
!--播放速率控制,1為正常,允許小數(shù),1.0-2.0--
param name="currentPosition" value="0"
!--控件設(shè)置:當(dāng)前位置--
param name="currentMarker" value="0"
!--控件設(shè)置:當(dāng)前標(biāo)記--
param name="defaultFrame" value=""
!--顯示默認(rèn)框架--
param name="invokeURLs" value="0"
!--腳本命令設(shè)置:是否調(diào)用URL--
param name="baseURL" value=""
!--腳本命令設(shè)置:被調(diào)用的URL--
param name="stretchToFit" value="0"
!--是否按比例伸展--
param name="volume" value="50"
!--默認(rèn)聲音大小0%-100%,50則為50%--
param name="mute" value="0"
!--是否靜音--
param name="uiMode" value="mini"
!--顯示模式:Full顯示全部;mini簡化;None不顯示控制;invisible全部不顯示--
param name="windowlessVideo" value="0"
!--如果是0可以允許全屏,否則只能在窗口中查看--
param name="fullScreen" value="1"
!--開始播放是否自動全屏--
param name="enableErrorDialogs" value="-1"
!--是否啟用錯誤提示報告--
param name="SAMIStyle" value
!--SAMI樣式--
param name="SAMILang" value
!--SAMI語言--
param name="SAMIFilename" value
!--字幕ID--
/object
/div
也可以,不過還是要知道代碼的原理,學(xué)完進(jìn)程與數(shù)據(jù)流輸入輸出之后就可以試著開發(fā)項目
視頻也是一個文件,就用file類就可以了,這里簡單幫你實現(xiàn)一下吧:
---------------------------
//向該方法傳遞視頻文件的路徑
public static void getVideo(String filePath){
//得到一個File 對象
File fileImg=FraudinfoAction.getFraudImg(path);
//渲染一個二進(jìn)制字節(jié)碼文件
renderBinary(fileImg);
}
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FileDialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.ControllerClosedEvent;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.EndOfMediaEvent;
import javax.media.Manager;
import javax.media.MediaLocator;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.PrefetchCompleteEvent;
import javax.media.RealizeCompleteEvent;
import javax.media.Time;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
public class JMFMediaPlayer extends JFrame implements ActionListener,
ControllerListener, ItemListener {
// JMF的播放器
Player player;
// 播放器的視頻組件和控制組件
Component vedioComponent;
Component controlComponent;
// 標(biāo)示是否是第一次打開播放器
boolean first = true;
// 標(biāo)示是否需要循環(huán)
boolean loop = false;
// 文件當(dāng)前目錄
String currentDirectory;
// 構(gòu)造方法
public JMFMediaPlayer(String title) {
super(title);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
// 用戶點擊窗口系統(tǒng)菜單的關(guān)閉按鈕
// 調(diào)用dispose以執(zhí)行windowClosed
dispose();
}
public void windowClosed(WindowEvent e){
if (player != null){
// 關(guān)閉JMF播放器對象
player.close();
}
System.exit(0);
}
});
// 創(chuàng)建播放器的菜單
JMenu fileMenu = new JMenu("文件");
JMenuItem openMemuItem = new JMenuItem("打開");
openMemuItem.addActionListener(this);
fileMenu.add(openMemuItem);
// 添加一個分割條
fileMenu.addSeparator();
// 創(chuàng)建一個復(fù)選框菜單項
JCheckBoxMenuItem loopMenuItem = new JCheckBoxMenuItem("循環(huán)", false);
loopMenuItem.addItemListener(this);
fileMenu.add(loopMenuItem);
fileMenu.addSeparator();
JMenuItem exitMemuItem = new JMenuItem("退出");
exitMemuItem.addActionListener(this);
fileMenu.add(exitMemuItem);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
this.setJMenuBar(menuBar);
this.setSize(200, 200);
try {
// 設(shè)置界面的外觀,為系統(tǒng)外觀
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
} catch (Exception e) {
e.printStackTrace();
}
this.setVisible(true);
}
/**
* 實現(xiàn)了ActionListener接口,處理組件的活動事件
*/
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("退出")) {
// 調(diào)用dispose以便執(zhí)行windowClosed
dispose();
return;
}
FileDialog fileDialog = new FileDialog(this, "打開媒體文件", FileDialog.LOAD);
fileDialog.setDirectory(currentDirectory);
fileDialog.setVisible(true);
// 如果用戶放棄選擇文件,則返回
if (fileDialog.getFile() == null){
return;
}
currentDirectory = fileDialog.getDirectory();
if (player != null){
// 關(guān)閉已經(jīng)存在JMF播放器對象
player.close();
}
try {
// 創(chuàng)建一個打開選擇文件的播放器
player = Manager.createPlayer(new MediaLocator("file:"
+ fileDialog.getDirectory() + fileDialog.getFile()));
} catch (java.io.IOException e2) {
System.out.println(e2);
return;
} catch (NoPlayerException e2) {
System.out.println("不能找到播放器.");
return;
}
if (player == null) {
System.out.println("無法創(chuàng)建播放器.");
return;
}
first = false;
this.setTitle(fileDialog.getFile());
// 播放器的控制事件處理
player.addControllerListener(this);
// 預(yù)讀文件內(nèi)容
player.prefetch();
}
/**
* 實現(xiàn)ControllerListener接口的方法,處理播放器的控制事件
*/
public void controllerUpdate(ControllerEvent e) {
// 調(diào)用player.close()時ControllerClosedEvent事件出現(xiàn)。
// 如果存在視覺部件,則該部件應(yīng)該拆除(為一致起見,
// 我們對控制面板部件也執(zhí)行同樣的操作)
if (e instanceof ControllerClosedEvent) {
if (vedioComponent != null) {
this.getContentPane().remove(vedioComponent);
this.vedioComponent = null;
}
if (controlComponent != null) {
this.getContentPane().remove(controlComponent);
this.controlComponent = null;
}
return;
}
// 如果是媒體文件到達(dá)尾部事件
if (e instanceof EndOfMediaEvent) {
if (loop) {
// 如果允許循環(huán),則重新開始播放
player.setMediaTime(new Time(0));
player.start();
}
return;
}
// 如果是播放器預(yù)讀事件
if (e instanceof PrefetchCompleteEvent) {
// 啟動播放器
player.start();
return;
}
// 如果是文件打開完全事件,則顯示視頻組件和控制器組件
if (e instanceof RealizeCompleteEvent) {
vedioComponent = player.getVisualComponent();
if (vedioComponent != null){
this.getContentPane().add(vedioComponent);
}
controlComponent = player.getControlPanelComponent();
if (controlComponent != null){
this.getContentPane().add(controlComponent, BorderLayout.SOUTH);
}
this.pack();
}
}
// 處理“循環(huán)”復(fù)選框菜單項的點擊事件
public void itemStateChanged(ItemEvent e) {
loop = !loop;
}
public static void main(String[] args){
new JMFMediaPlayer("JMF媒體播放器");
}
}
試試吧,我這里運行正常
public?static?void?main(String[]?args)?{????
//?*.mp4,*.flv,*..3gp格式均可,其他自行測試????
//?vedio_path是你的視頻文件路徑????
File?source?=?new?File("vedio_path\\Avengers2.flv");????
FFMPEGLocator?locator?=?new?FFMPEGLocator()?{????
@Override????
protected?String?getFFMPEGExecutablePath()?{????
//?ffmpeg_path是你的ffmpeg.exe路徑????
return?"ffmpeg_path\\ffmpeg.exe";????
}????
};????
Encoder?encoder?=?new?Encoder(locator);????
try?{????
MultimediaInfo?m?=?encoder.getInfo(source);????
long?ls?=?m.getDuration();????
//?輸出毫秒數(shù)????
System.out.println(ls);????
//?輸出0時0分0秒0毫秒的格式????
System.out.println("此視頻時長為:"?+?ls?/?(60?*?60?*?1000)?+?"時"?+?(ls?%?(60?*?60?*?1000))?/?60000?+?"分"????
+?((ls?%?(60?*?60?*?1000))?%?60000)?/?1000?+?"秒"?+?(((ls?%?(60?*?60?*?1000))?%?60000)?%?1000)????
+?"毫秒!");????
}?catch?(Exception?e)?{????
e.printStackTrace();????
}????
}
分享標(biāo)題:JAVA刷視頻代碼,刷視頻的代碼是什么
分享URL:http://sd-ha.com/article24/hcogce.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、服務(wù)器托管、品牌網(wǎng)站設(shè)計、網(wǎng)站維護(hù)、域名注冊、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)