Skip to main content

help with MediaPlayer

1 reply [Last post]
jiyuu
Offline
Joined: 2008-10-13

I'm testing the JavaFX media functions. I took some code from a tutorial and mixed it with my own code. I have a video with autoplay false. When I click a button, the movie starts. When I click anonther button, the movie stops. I have repeat: REPEAT_NONE. And now I want to start the movie again when I press another button - but i don't know how. I have tried a lot of things, but nothing works.

Any idea?

Code:

import javafx.ext.swing.*;
import javafx.scene.paint.*;
import javafx.scene.geometry.*;
import javafx.scene.media.*;
import javafx.scene.text.*;
import javafx.scene.*;
import java.lang.*;
import javafx.input.*;

public class PlayVideo {

// Set mediaURL (mp3, wmv or any supported ext)
private attribute mediaURL = "{__DIR__}/wakeboard.wmv";

// this is the mediaplayer.
private attribute player:MediaPlayer = MediaPlayer {
media: Media {
source: mediaURL;

}
// don't play by default
autoPlay: false
// do not repeat the media :)
repeatCount: MediaPlayer.REPEAT_NONE

}

attribute frame:SwingFrame = SwingFrame {

content: Canvas {

content: [

MediaView {
mediaPlayer: player
},

Group {

content: [

Rectangle {

width: 100
height: 50
fill: Color.WHITE

onMousePressed: function(e:MouseEvent):Void {
player.play();
}

},

Text {
content: "Start"
fill: Color.BLACK
translateX: 36
translateY: 34
},

Rectangle {

width: 100
height: 50
fill: Color.WHITE
x: 110
y: 1
onMousePressed: function(e:MouseEvent):Void {
player.pause();
}

},

Text {
content: "Pause"
fill: Color.BLACK
x: 150
y: 30
}
]

translateX: 10
translateY: 10

},

Circle {
centerX: 100, centerY: 100
radius: 40
fill: Color.RED

onMousePressed: function( e: MouseEvent ):Void {
// re-start the movie?
}
}

]

}

visible: true
closeAction: function() {
player.pause();
frame.close();
System.exit(0);
}
title: "Close window to exit"
}

}

var app:PlayVideo = PlayVideo{}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
wildhias
Offline
Joined: 2008-11-04

hi: I am facing the same problem in Javafx.

I have a mediaplayer mp and want to play the sound each time i press an object with:

onMousePressed: function(e ): Void{
mp.play()
}

I can only do it once. How should I do to let it play each time I press the mouse?

I would be grateful for advice