swing如何播放视屏文件???

shewen45 2012-11-23 05:36:06
jmf可以播放视屏 但是我这里文件拿过来就是mp4格式的 不可能让我中间去转码吧。。。。
java除了jmf还有别的方式可以播放视屏文件的没??
...全文
629 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
明证真道 2015-06-29
  • 打赏
  • 举报
回复
同楼上问一问啊,不知道楼主是否能看见,望解答啊。
破Feel 2014-03-05
  • 打赏
  • 举报
回复
楼主,最后怎么解决的,我也有你的需求
shewen45 2012-11-26
  • 打赏
  • 举报
回复
我把MP4文件放到src 下 则: Exception in thread "main" java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403) at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47) at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115) at java.lang.Thread.run(Thread.java:662) Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:232) at javafx.scene.media.Media.<init>(Media.java:364) at StreamingMediaPlayer.init(StreamingMediaPlayer.java:101) at StreamingMediaPlayer.start(StreamingMediaPlayer.java:722) at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206) at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29) at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73) ... 1 more
shewen45 2012-11-26
  • 打赏
  • 举报
回复
引用 13 楼 huntor 的回复:
什么错误? new Media(mediafile.toURI())
mediaPlayer = new MediaPlayer(new Media(MEDIA_URL)); 这里的 MEDIA_URL 是网络视屏地址 但是我现在要加载的是本地视屏 如: private static final String MEDIA_URL = "C:\\DownLoad\\192.168.1.1681Time20121123090000Time20121123090010.mp4"; 则: Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\DownLoad\192.168.1.1681Time20121123090000Time20121123090010.mp4 at java.net.URI$Parser.fail(URI.java:2810) at java.net.URI$Parser.checkChars(URI.java:2983) at java.net.URI$Parser.parse(URI.java:3020) at java.net.URI.<init>(URI.java:577) at javafx.scene.media.Media.<init>(Media.java:357) ... 9 more
huntor 2012-11-26
  • 打赏
  • 举报
回复
什么错误? new Media(mediafile.toURI())
shewen45 2012-11-26
  • 打赏
  • 举报
回复
引用 10 楼 huntor 的回复:
引用 8 楼 shewen45 的回复:引用 7 楼 huntor 的回复:不使用swing,使用 javafx,自带多媒体播放。 我这里工程就是swing做的cs项目 javafx是第三方的么? 可以嵌套到swing里么? javafx2中的JFXPanel可以把JavaFX组件嵌入swing程序中。
你好 请问有嵌入视屏的demo么 javafx以前没接触过 刚才看了下demo 里面加载的都是网络上的视屏 我加载本地视屏报错!! 还请指教
shewen45 2012-11-26
  • 打赏
  • 举报
回复
引用 2 楼 geminit2011 的回复:
不一定非要使用jmf,只是建议:
http://blog.csdn.net/geminit2011/article/details/7682879
这是我写的,其中的NativeSwing中有一个vlc player可以实现播放mp4。
代码:Java code?1234567891011121314151617181920212223242526272829303……


大哥 我界面运行出来了 可以加载MP4视屏文件的时候
弹出这个提示框 求教如何解决 ‘我在网上试过的办法没能解决’ 还请指教
shewen45 2012-11-26
  • 打赏
  • 举报
回复
感谢楼上2位大神的回答 可惜我就20分了 您二位将就下吧
Geminit 2012-11-26
  • 打赏
  • 举报
回复
package media.player;

import javafx.scene.control.Label;
import javafx.scene.control.Slider;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaPlayer.Status;
import javafx.scene.media.MediaView;
import javafx.util.Duration;
import javafx.application.Platform;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;

public class MediaControl extends BorderPane {
	private MediaPlayer mp;
	private MediaView mediaView;
	private final boolean repeat = false;
	private boolean stopRequested = false;
	private boolean atEndOfMedia = false;
	private Duration duration;
	private Slider timeSlider;
	private Label playTime;
	private Slider volumeSlider;
	private HBox mediaBar;

	public MediaControl(final MediaPlayer mp) {
		this.mp = mp;
		setStyle("-fx-background-color: #bfc2c7;");
		mediaView = new MediaView(mp);
		Pane mvPane = new Pane() {
		};
		mvPane.getChildren().add(mediaView);
		mvPane.setStyle("-fx-background-color: black;");
		setCenter(mvPane);

		mediaBar = new HBox();
		mediaBar.setAlignment(Pos.CENTER);
		mediaBar.setPadding(new Insets(5, 10, 5, 10));
		BorderPane.setAlignment(mediaBar, Pos.CENTER);

		final Button playButton = new Button(">");
		mediaBar.getChildren().add(playButton);
		playButton.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent e) {
				Status status = mp.getStatus();
				if (status == Status.UNKNOWN || status == Status.HALTED) {
					// don't do anything in these states
					return;
				}

				if (status == Status.PAUSED || status == Status.READY
						|| status == Status.STOPPED) {
					// rewind the movie if we're sitting at the end
					if (atEndOfMedia) {
						mp.seek(mp.getStartTime());
						atEndOfMedia = false;
					}
					mp.play();
				} else {
					mp.pause();
				}
			}
		});
		setBottom(mediaBar);
		
		mp.currentTimeProperty().addListener(
				new InvalidationListener() {
					public void invalidated(Observable ov) {
						updateValues();
					}
				});

		mp.setOnPlaying(new Runnable() {
			public void run() {
				if (stopRequested) {
					mp.pause();
					stopRequested = false;
				} else {
					playButton.setText("||");
				}
			}
		});

		mp.setOnPaused(new Runnable() {
			public void run() {
				System.out.println("onPaused");
				playButton.setText(">");
			}
		});

		mp.setOnReady(new Runnable() {
			public void run() {
				duration = mp.getMedia().getDuration();
				updateValues();
			}
		});

		mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
		mp.setOnEndOfMedia(new Runnable() {
			public void run() {
				if (!repeat) {
					playButton.setText(">");
					stopRequested = true;
					atEndOfMedia = true;
				}
			}
		});

		// Add spacer
		Label spacer = new Label("   ");
		mediaBar.getChildren().add(spacer);

		// Add Time label
		Label timeLabel = new Label("Time: ");
		mediaBar.getChildren().add(timeLabel);

		// Add time slider
		timeSlider = new Slider();
		HBox.setHgrow(timeSlider, Priority.ALWAYS);
		timeSlider.setMinWidth(50);
		timeSlider.setMaxWidth(Double.MAX_VALUE);
		timeSlider.valueProperty().addListener(new InvalidationListener() {
			public void invalidated(Observable ov) {
				if (timeSlider.isValueChanging()) {
					// multiply duration by percentage calculated by slider
					// position
					mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
				}
			}
		});
		mediaBar.getChildren().add(timeSlider);

		// Add Play label
		playTime = new Label();
		playTime.setPrefWidth(130);
		playTime.setMinWidth(50);
		mediaBar.getChildren().add(playTime);

		// Add the volume label
		Label volumeLabel = new Label("Vol: ");
		mediaBar.getChildren().add(volumeLabel);

		// Add Volume slider
		volumeSlider = new Slider();
		volumeSlider.setPrefWidth(70);
		volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
		volumeSlider.setMinWidth(30);
		volumeSlider.valueProperty().addListener(new InvalidationListener() {
			public void invalidated(Observable ov) {
				if (volumeSlider.isValueChanging()) {
					mp.setVolume(volumeSlider.getValue() / 100.0);
				}
			}
		});
		mediaBar.getChildren().add(volumeSlider);
	}

	protected void updateValues() {
		if (playTime != null && timeSlider != null && volumeSlider != null) {
			Platform.runLater(new Runnable() {
				public void run() {
					Duration currentTime = mp.getCurrentTime();
					playTime.setText(formatTime(currentTime, duration));
					timeSlider.setDisable(duration.isUnknown());
					if (!timeSlider.isDisabled()
							&& duration.greaterThan(Duration.ZERO)
							&& !timeSlider.isValueChanging()) {
						timeSlider.setValue(currentTime.divide(duration)
								.toMillis() * 100.0);
					}
					if (!volumeSlider.isValueChanging()) {
						volumeSlider.setValue((int) Math.round(mp.getVolume() * 100));
					}
				}
			});
		}
	}

	private static String formatTime(Duration elapsed, Duration duration) {
		int intElapsed = (int) Math.floor(elapsed.toSeconds());
		int elapsedHours = intElapsed / (60 * 60);
		if (elapsedHours > 0) {
			intElapsed -= elapsedHours * 60 * 60;
		}
		int elapsedMinutes = intElapsed / 60;
		int elapsedSeconds = intElapsed - elapsedHours * 60 * 60
				- elapsedMinutes * 60;

		if (duration.greaterThan(Duration.ZERO)) {
			int intDuration = (int) Math.floor(duration.toSeconds());
			int durationHours = intDuration / (60 * 60);
			if (durationHours > 0) {
				intDuration -= durationHours * 60 * 60;
			}
			int durationMinutes = intDuration / 60;
			int durationSeconds = intDuration - durationHours * 60 * 60
					- durationMinutes * 60;
			if (durationHours > 0) {
				return String.format("%d:%02d:%02d/%d:%02d:%02d", elapsedHours,
						elapsedMinutes, elapsedSeconds, durationHours,
						durationMinutes, durationSeconds);
			} else {
				return String.format("%02d:%02d/%02d:%02d", elapsedMinutes,
						elapsedSeconds, durationMinutes, durationSeconds);
			}
		} else {
			if (elapsedHours > 0) {
				return String.format("%d:%02d:%02d", elapsedHours,
						elapsedMinutes, elapsedSeconds);
			} else {
				return String.format("%02d:%02d", elapsedMinutes,
						elapsedSeconds);
			}
		}
	}
}
Geminit 2012-11-26
  • 打赏
  • 举报
回复
oracle官网关于javafx支持media的代码demo

package media.player;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

public class EmbeddedMediaPlayer extends Application {
	private static final String MEDIA_URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";

	@Override
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Embedded Media Player");
		Group root = new Group();
		Scene scene = new Scene(root, 540, 210);

		primaryStage.setScene(scene);
		primaryStage.show();

		// create media player
		Media media = new Media(MEDIA_URL);
		MediaPlayer mediaPlayer = new MediaPlayer(media);
		mediaPlayer.setAutoPlay(true);

		// create mediaView and add media player to the viewer
		MediaView mediaView = new MediaView(mediaPlayer);
		((Group) scene.getRoot()).getChildren().add(mediaView);
		
		MediaControl mediaControl = new MediaControl(mediaPlayer);
		scene.setRoot(mediaControl);
	}
	
	public static void main(String[] args) {
		Application.launch(args);
	}
}
Geminit 2012-11-26
  • 打赏
  • 举报
回复
引用 19 楼 shewen45 的回复:
引用 18 楼 geminit2011 的回复:目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。
mp4本身在手机应用比较多,如果是桌面应用,可以考虑使用javafx+flv的形式,前提是你需要格式转换。 否则,只有寻找含有mp4解码器的java支持播放组件。
shewen45 2012-11-26
  • 打赏
  • 举报
回复
引用 18 楼 geminit2011 的回复:
目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。
Geminit 2012-11-26
  • 打赏
  • 举报
回复
目前只支持flv,mp3和一些http的流媒体而已……mp4尚不在其支持的范围之内。
Geminit 2012-11-26
  • 打赏
  • 举报
回复
引用 16 楼 huntor 的回复:
你不看文档。Media的参数是一个URI格式的字符串。支持 http、file、jar协议。 http://............mp4 file:/.........mp4 上面那个写错了 new Media("file:/D:/Temp/LaTeXDraw2.0.8/data/LaTeXDraw.avi")
你看下javafx的文档 Some of the features supported by the JavaFX media stack include the following: FLV container with MP3 and VP6 MP3 audio MPEG-4 container with either AAC, H.264, or both HTTP, FILE protocol support Progressive download Seeking Buffer progress Playback functions (Play, Pause, Stop, Volume, Mute, Balance, Equalizer)
huntor 2012-11-26
  • 打赏
  • 举报
回复
你不看文档。Media的参数是一个URI格式的字符串。支持 http、file、jar协议。 http://............mp4 file:/.........mp4 上面那个写错了 new Media("file:/D:/Temp/LaTeXDraw2.0.8/data/LaTeXDraw.avi")
huntor 2012-11-24
  • 打赏
  • 举报
回复
引用 8 楼 shewen45 的回复:
引用 7 楼 huntor 的回复:不使用swing,使用 javafx,自带多媒体播放。 我这里工程就是swing做的cs项目 javafx是第三方的么? 可以嵌套到swing里么?
javafx2中的JFXPanel可以把JavaFX组件嵌入swing程序中。
shewen45 2012-11-23
  • 打赏
  • 举报
回复
引用 7 楼 huntor 的回复:
不使用swing,使用 javafx,自带多媒体播放。
我这里工程就是swing做的cs项目 javafx是第三方的么? 可以嵌套到swing里么?
huntor 2012-11-23
  • 打赏
  • 举报
回复
不使用swing,使用 javafx,自带多媒体播放。
shewen45 2012-11-23
  • 打赏
  • 举报
回复
好的 我先试试 谢
Geminit 2012-11-23
  • 打赏
  • 举报
回复
下载不行就等会上我的资源去下载 我传上去了 估计要审批一会 叫swt jar包
加载更多回复(4)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧