JMF這個(gè)多媒體開(kāi)發(fā)框架太牛了,簡(jiǎn)單的幾句代碼就能實(shí)現(xiàn)一個(gè)視頻播放器的開(kāi)發(fā),厲害,就是支持的格式少了一些,沒(méi)關(guān)系,這個(gè)視頻播放器可以播放mpg,avi,fvl等等,想播放其他的請(qǐng)開(kāi)發(fā)自己的插件,下面將代碼貼上去
目前累計(jì)服務(wù)客戶上千多家,積累了豐富的產(chǎn)品開(kāi)發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹(shù)立企業(yè)形象,為客戶提供網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、網(wǎng)站策劃、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)絡(luò)營(yíng)銷(xiāo)、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。創(chuàng)新互聯(lián)公司始終以務(wù)實(shí)、誠(chéng)信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過(guò)對(duì)領(lǐng)先技術(shù)的掌握、對(duì)創(chuàng)意設(shè)計(jì)的研究、對(duì)客戶形象的視覺(jué)傳遞、對(duì)應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。package com.bird.jmf; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Panel; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.media.CannotRealizeException; 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; @SuppressWarnings({ "restriction", "unused" }) public class JMFSample implements ControllerListener { public static void main(String[] args) { JMFSample sp = new JMFSample(); sp.play(); } private Player mediaPlayer; private Frame f; private Player player; private Panel panel; private Component visual; private Component control = null; public void play(){ f = new Frame("JMF Sample1"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { if(player != null) { player.close(); } System.exit(0); } }); f.setSize(500,400); f.setVisible(true); URL url = null; try { //準(zhǔn)備一個(gè)要播放的視頻文件的URL url = new URL("file:/d:/2.mpg"); } catch (MalformedURLException e) { e.printStackTrace(); } try { //通過(guò)調(diào)用Manager的createPlayer方法來(lái)創(chuàng)建一個(gè)Player的對(duì)象 //這個(gè)對(duì)象是媒體播放的核心控制對(duì)象 player = Manager.createPlayer(url); } catch (NoPlayerException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } //對(duì)player對(duì)象注冊(cè)監(jiān)聽(tīng)器,能噶偶在相關(guān)事件發(fā)生的時(shí)候執(zhí)行相關(guān)的動(dòng)作 player.addControllerListener(this); //讓player對(duì)象進(jìn)行相關(guān)的資源分配 player.realize(); } private int videoWidth = 0; private int videoHeight = 0; private int controlHeight = 30; private int insetWidth = 10; private int insetHeight = 30; //監(jiān)聽(tīng)player的相關(guān)事件 public void controllerUpdate(ControllerEvent ce) { if (ce instanceof RealizeCompleteEvent) { //player實(shí)例化完成后進(jìn)行player播放前預(yù)處理 player.prefetch(); } else if (ce instanceof PrefetchCompleteEvent) { if (visual != null) return; //取得player中的播放視頻的組件,并得到視頻窗口的大小 //然后把視頻窗口的組件添加到Frame窗口中, if ((visual = player.getVisualComponent()) != null) { Dimension size = visual.getPreferredSize(); videoWidth = size.width; videoHeight = size.height; f.add(visual); } else { videoWidth = 320; } //取得player中的視頻播放控制條組件,并把該組件添加到Frame窗口中 if ((control = player.getControlPanelComponent()) != null) { controlHeight = control.getPreferredSize().height; f.add(control, BorderLayout.SOUTH); } //設(shè)定Frame窗口的大小,使得滿足視頻文件的默認(rèn)大小 f.setSize(videoWidth + insetWidth, videoHeight + controlHeight + insetHeight); f.validate(); //啟動(dòng)視頻播放組件開(kāi)始播放 player.start(); mediaPlayer.start(); } else if (ce instanceof EndOfMediaEvent) { //當(dāng)播放視頻完成后,把時(shí)間進(jìn)度條恢復(fù)到開(kāi)始,并再次重新開(kāi)始播放 player.setMediaTime(new Time(0)); player.start(); } } }
文章標(biāo)題:使用JMF實(shí)現(xiàn)java視頻播放器-創(chuàng)新互聯(lián)
文章URL:http://m.rwnh.cn/article38/djiesp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、虛擬主機(jī)、小程序開(kāi)發(fā)、自適應(yīng)網(wǎng)站、做網(wǎng)站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容