Part one Part TWO Part Three Part FOUR

  • Slides: 24
Download presentation

Part one 绪论

Part one 绪论

Part TWO 概要

Part TWO 概要

Part Three 需求

Part Three 需求

Part FOUR 设计

Part FOUR 设计

Part FIVE 程序

Part FIVE 程序

界面模块分析 1://需要把多媒体文件放置到运行的目录下 private static final String myurl ="D: \张艺兴. mp 4"; public void start(Stage

界面模块分析 1://需要把多媒体文件放置到运行的目录下 private static final String myurl ="D: \张艺兴. mp 4"; public void start(Stage primary. Stage) throws Exception{ File file=new File(myurl); Group root = new Group(); //设置界面 Scene scene = new Scene(root, 1280, 720); // Media media = new Media(MEDIA_URL); Media media = new Media(file. to. URI(). to. String()); //创建播放器对象,控制媒体播放行为 Media. Player media. Player=new Media. Player(media); media. Player. set. Auto. Play(true); //设置自动播放 5. media. Player. set. Cycle. Count(Media. Player. INDEFINITE); //设置循环播放(设置播放次数) Controller media. Control=new Controller(media. Player); scene. set. Root(media. Control); //Parent root = FXMLLoader. load(get. Class(). get. Resource("sample. fxml")); primary. Stage. set. Title("media. Player"); primary. Stage. set. Scene(scene); primary. Stage. show(); }

界面模块分析 private Media. Player mp; private Media. View media. View; //父类窗口 private final boolean

界面模块分析 private Media. Player mp; private Media. View media. View; //父类窗口 private final boolean repeat = false; //记录视频是否重 复播放 private boolean stop. Requested = false; //记录视频是否停 止 private boolean at. End. Of. Media = false; private Duration duration; //记录视频持续时间 private Slider time. Slider; private Label play. Time; private Slider volume. Slider; private HBox media. Bar; public Controller(final Media. Player mp) { this. mp = mp; set. Style("-fx-background-color: #bfc 2 c 7; "); media. View = new Media. View(mp); Pane mv. Pane = new Pane() {}; mv. Pane. get. Children(). add(media. View); mv. Pane. set. Style("-fxbackground-color: black; "); set. Center(mv. Pane); media. Bar = new HBox(); media. Bar. set. Alignment(Pos. CENTER); media. Bar. set. Padding(new jav afx. geometry. Insets(5, 10, 5, 10)); media. Bar. set. Padding(new Ins ets(5, 10, 5, 10)); Border. Pane. set. Alignment(me dia. Bar, Pos. CENTER); final Button play. Button = new Button(">");

音量模块分析 Label volume. Label = new Label("Vol: "); media. Bar. get. Children(). add(volume. Label);

音量模块分析 Label volume. Label = new Label("Vol: "); media. Bar. get. Children(). add(volume. Label); // Add Volume slider volume. Slider = new Slider(); volume. Slider. set. Pref. Width(70); volume. Slider. set. Max. Width( Region. USE_PREF_SIZE); volume. Slider. set. Min. Width(30); volume. Slider. value. Property(). add. Listener(new Invalidatio n. Listener() { public void invalidated(Observable ov) { if (volume. Slider. is. Value. Changing()) { mp. set. Volume(volume. Slider. get. Valu e() / 100. 0); } } }); media. Bar. get. Children(). add(volume. Slider); set. Bottom(media. Bar);

暂停模块分析 //设置播放按钮动作 public void handle(Action. Event e) { Media. Player. Status status = mp.

暂停模块分析 //设置播放按钮动作 public void handle(Action. Event e) { Media. Player. Status status = mp. get. Status(); if (status == Media. Player. Status. UNKNOWN || status == Media. Player. Status. HALTED) { // don't do anything in t hese states return; } //当资源处于暂停或停止状态时 if (status == Media. Player. Status. PAUSED || status == Media. Player. Status. READY || status == Media. Player. Status. STOPPED) { // rewind the movie if we're sitting at the end if (at. End. Of. Media) { mp. seek(mp. get. Start. Time()); at. End. Of. Media = false; } mp. play(); } else { mp. pause(); } }

进度条模块分析 // Add spacer. Label spacer = new Label(" "); media. Bar. get. Children().

进度条模块分析 // Add spacer. Label spacer = new Label(" "); media. Bar. get. Children(). add(spacer); // Add Time label. Label time. Label = new Label("Time: "); media. Bar. get. Children(). add(time. Label); // Add time slidertime. Slider = new Slider(); HBox. set. Hgrow(time. Slider, Priority. ALWAYS); time. Slider. set. Min. Width(50); time. Slider. set. M ax. Width(Double. MAX_VALUE); time. Slider. value. Property(). add. Lis tener(new Invalidation. Listener() {public void invalidated(Observable ov) {if (time. Slider. is. Value. Changing()) {// multiply duration by percentage calculated by slider positionmp. seek(duration. multiply(time. Slider. get. Value() / 100. 0)); }}}); media. Bar. get. Children(). add(time. Slider);

Part SIX 运行

Part SIX 运行

Part SIX 结论

Part SIX 结论

Thank you

Thank you