Here is my Code, any one can me tell how to stop playing media file, In this EmbeddedMediaPlayerComponent is class used to play Media file.... My question to you How to stop media file...
public class MediaPlayer extends JPanel {
//Declares our media player component
private EmbeddedMediaPlayerComponent[] mediaplayer;
private String[] mediapath = {""};
private final String vlcpath = "C:\\Program Files (x86)\\VideoLAN\\VLC";
private JPanel video_pnl, control_pnl;
private JButton[] play_btn, stop_btn;
private int but = 0;
public MediaPlayer(String mediapath[]) {
this.mediapath = mediapath;
play_btn = new JButton[1];
stop_btn = new JButton[1];
mediaplayer = new EmbeddedMediaPlayerComponent[1];
int increment = 0;
while (increment < mediapath.length) {
video_pnl = new JPanel();
video_pnl.setLayout(new BorderLayout());
control_pnl = new JPanel();
control_pnl.setLayout(new FlowLayout(FlowLayout.CENTER));
for (int i = 0; i < 1; i++) {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), vlcpath);
mediaplayer[i] = new EmbeddedMediaPlayerComponent();
play_btn[i] = new JButton("play");
stop_btn[i] = new JButton("stop");
video_pnl.add(mediaplayer[i], BorderLayout.CENTER);
control_pnl.add(play_btn[i]);
control_pnl.add(stop_btn[i]);
video_pnl.add(control_pnl, BorderLayout.SOUTH);
Handler handler = new Handler();
play_btn[i].addActionListener(handler);
}
add(video_pnl);
increment++;
}
}
private class Handler implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == play_btn){
play();
}
}
}
public void play() {
for (int i = 0; i < mediapath.length; i++) {
mediaplayer[i].getMediaPlayer().playMedia(mediapath[i]);
}
}
public static void main(String[] args) {
//Declare and initialize local variables
String[] mediaPath = {"C:\\\\Users\\\\goldAnthony\\\\Desktop\\\\Videos\\\\Whistle.mp4", "C:\\\\Users\\\\goldAnthony\\\\Desktop\\\\Videos\\\\Beyonce_Hello.mp4",
"C:\\Users\\goldAnthony\\Desktop\\Videos\\HansRosling_2012S_480p.mp4","C:\\Users\\goldAnthony\\Desktop\\Videos\\oow2010_2.mp4",
"C:\\Users\\goldAnthony\\Desktop\\Videos\\The_Economic_Environment.mp4"};
//creates instances of the VlcPlayer object, pass the mediaPath and invokes the method "run"
MediaPlayer mediaplayer = new MediaPlayer(mediaPath);
JFrame ourframe = new JFrame();
ourframe.setContentPane(mediaplayer);
ourframe.setLayout(new GridLayout(5, 1));
ourframe.setSize(300, 560);
ourframe.setVisible(true);
mediaplayer.play();
ourframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}