/*
* This file is part of VLCJ.
*
* VLCJ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VLCJ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2009, 2010, 2011 Caprica Software Limited.
*/
package uk.co.vlc.demo;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.DefaultFullScreenStrategy;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.FullScreenStrategy;
import uk.co.vlc.test.VlcjTest;
/**
* Example multi-instance player.
* <p>
* This approach to multi-instance players is not really recommended due to
* potential concurrency/re-entrancy problems with the long list of native
* libraries that vlc uses. The more player instances you have in one
* application, the more likely you are to see fatal crashes in those native
* libraries.
* <p>
* Also, a current limitation of vlc is that all in-process media players will
* share the same audio controls - there is no independent audio control
* available.
* <p>
* Out of process media players are reliable, but a lot more difficult and
* intricate to implement.
*/
public class TestMultiPlayer extends VlcjTest {
/**
* 指定视频位置,可以多个
*/
private String[] medias = { "F:\\hello.rmvb"
// Your MRL's go here
};
private int rows = 1;
private int cols = 4;
private Frame mainFrame;
private List<PlayerInstance> players = new ArrayList<PlayerInstance>();
private MediaPlayerFactory factory;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new TestMultiPlayer().start();
}
});
}
public TestMultiPlayer() {
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.black);
contentPane.setLayout(new GridLayout(rows, cols, 16, 16));
contentPane.setBorder(new EmptyBorder(16, 16, 16, 16));
mainFrame = new Frame("VLCJ Test Multi Player for VLC 1.2.x");
// mainFrame.setIconImage(new
// ImageIcon(getClass().getResource("/icons/vlcj-logo.png")).getImage());
mainFrame.setLayout(new BorderLayout());
mainFrame.setBackground(Color.black);
mainFrame.add(contentPane, BorderLayout.CENTER);
mainFrame.setBounds(100, 100, 1600, 300);
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
for (PlayerInstance pi : players) {
pi.mediaPlayer().release();
}
factory.release();
System.exit(0);
}
});
mainFrame.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
for (int i = 0; i < players.size(); i++) {
players.get(i).mediaPlayer().pause();
}
}
});
factory = new MediaPlayerFactory("no-title");
FullScreenStrategy fullScreenStrategy = new DefaultFullScreenStrategy(
mainFrame);
for (int i = 0; i < medias.length; i++) {
EmbeddedMediaPlayer player = factory
.newEmbeddedMediaPlayer(fullScreenStrategy);
PlayerInstance playerInstance = new PlayerInstance(player);
players.add(playerInstance);
JPanel playerPanel = new JPanel();
playerPanel.setLayout(new BorderLayout());
playerPanel.setBorder(new LineBorder(Color.white, 2));
playerPanel.add(playerInstance.videoSurface());
contentPane.add(playerPanel);
}
mainFrame.setVisible(true);
}
private void start() {
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
for (int i = 0; i < medias.length; i++) {
players.get(i)
.mediaPlayer()
.setVideoSurface(
factory.newVideoSurface(players.get(i)
.videoSurface()));
players.get(i).mediaPlayer().prepareMedia(medias[i], "1");
}
// There is a race condition somewhere when invoking
// libvlc_media_player_play()
// multiple times in quick succession that causes a hard-failure
// and a fatal
// VM crash.
//
// This is _not_ about _concurrently_ calling play multiple
// times, but the
// native play function call must be off-loading something to a
// separate
// thread and returning - then a subsequent call to play somehow
// interferes
// with that or fails because of that.
//
// When libvlc_media_player_play() is called, the video playback
// is kicked
// off asynchronously - so the API call will return before the
// video has
// started playing. If we invoke play and then wait (making this
// effectively
// a synchronous call) for the player to start playing, the hard
// VM crash
// does not occur
for (int i = 0; i < medias.length; i++) {
EmbeddedMediaPlayer mediaPlayer = players.get(i)
.mediaPlayer();
mediaPlayer.start();
}
}
});
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于vlcj的java视频播放器,支持多格式 (314个子文件)
hello.avi 7.64MB
TestMultiPlayer.class 4KB
VlcjTest.class 2KB
PlayerInstance.class 2KB
TestMultiPlayer$4.class 2KB
TestMultiPlayer$2.class 1KB
TestMultiPlayer$3.class 1KB
TestMultiPlayer$1.class 607B
.classpath 538B
plugins.dat 338KB
libqt4_plugin.dll 11.05MB
libavcodec_plugin.dll 9.09MB
libskins2_plugin.dll 2.18MB
libvlccore.dll 2.18MB
libgnutls_plugin.dll 1.93MB
libvorbis_plugin.dll 1.64MB
libsamplerate_plugin.dll 1.45MB
libprojectm_plugin.dll 1.4MB
libzvbi_plugin.dll 1.33MB
libtaglib_plugin.dll 1.24MB
libschroedinger_plugin.dll 1.2MB
libxml_plugin.dll 1.18MB
libmkv_plugin.dll 1.16MB
libx264_plugin.dll 1.15MB
libsid_plugin.dll 951KB
liblibass_plugin.dll 914KB
libcaca_plugin.dll 751KB
libstream_filter_dash_plugin.dll 708KB
libfreetype_plugin.dll 680KB
liblive555_plugin.dll 656KB
libmod_plugin.dll 474KB
libstream_out_rtp_plugin.dll 468KB
libstream_filter_httplive_plugin.dll 436KB
librtp_plugin.dll 413KB
libstream_out_raop_plugin.dll 411KB
libremoteosd_plugin.dll 409KB
libaccess_output_shout_plugin.dll 405KB
libgme_plugin.dll 401KB
libtheora_plugin.dll 378KB
libfaad_plugin.dll 363KB
libswscale_plugin.dll 362KB
liblua_plugin.dll 302KB
libupnp_plugin.dll 279KB
libflac_plugin.dll 259KB
libfluidsynth_plugin.dll 257KB
libdvdnav_plugin.dll 253KB
libgoom_plugin.dll 229KB
liblibbluray_plugin.dll 228KB
libdshow_plugin.dll 215KB
libmp4_plugin.dll 192KB
libblend_plugin.dll 190KB
libdeinterlace_plugin.dll 184KB
libpng_plugin.dll 181KB
libdtstofloat32_plugin.dll 178KB
libatmo_plugin.dll 177KB
libdvdread_plugin.dll 175KB
liblibmpeg2_plugin.dll 163KB
libdtv_plugin.dll 160KB
libdvbsub_plugin.dll 151KB
libtwolame_plugin.dll 151KB
libspeex_plugin.dll 151KB
libi420_rgb_sse2_plugin.dll 136KB
libmpgatofixed32_plugin.dll 132KB
libts_plugin.dll 132KB
libmux_ts_plugin.dll 129KB
libcdda_plugin.dll 128KB
libvlc.dll 109KB
libspatializer_plugin.dll 105KB
libplaylist_plugin.dll 104KB
libogg_plugin.dll 99KB
libkate_plugin.dll 96KB
libmpc_plugin.dll 94KB
libmux_ps_plugin.dll 93KB
libaccess_bd_plugin.dll 92KB
libavi_plugin.dll 90KB
libaccess_http_plugin.dll 90KB
libpacketizer_h264_plugin.dll 85KB
libpostproc_plugin.dll 84KB
libsap_plugin.dll 83KB
libzip_plugin.dll 82KB
libaccess_mms_plugin.dll 78KB
libi420_rgb_mmx_plugin.dll 76KB
libasf_plugin.dll 72KB
libaccess_realrtsp_plugin.dll 71KB
liboldrc_plugin.dll 70KB
libdirectx_plugin.dll 69KB
libdirect3d_plugin.dll 69KB
libstream_out_transcode_plugin.dll 69KB
liba52tofloat32_plugin.dll 68KB
libglwin32_plugin.dll 67KB
libvisual_plugin.dll 64KB
libvod_rtsp_plugin.dll 58KB
libpanoramix_plugin.dll 56KB
libpacketizer_mpeg4audio_plugin.dll 56KB
libty_plugin.dll 56KB
libwingdi_plugin.dll 55KB
libi420_rgb_plugin.dll 55KB
libmux_mp4_plugin.dll 55KB
libdirect2d_plugin.dll 55KB
libaudiobargraph_v_plugin.dll 55KB
共 314 条
- 1
- 2
- 3
- 4
yutianzhijie
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页