Parent: [a7a9ff] (diff)

Download this file

MediaPlayerView.java    142 lines (126 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Copyright 2013-2014 TECO - Karlsruhe Institute of Technology.
*
* This file is part of TACET.
*
* TACET 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.
*
* TACET 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 TACET. If not, see <http://www.gnu.org/licenses/>.
*/
package squirrel.view.video;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.JPanel;
import squirrel.controller.video.MainController;
import squirrel.controller.video.MediaPlayerControlsController;
import squirrel.controller.video.RemoteController;
import com.sun.jna.Native;
/**
* The Class MediaPlayerView.
*/
@SuppressWarnings("serial")
public class MediaPlayerView extends JPanel {
private Canvas canvas;
private MediaPlayerControls controls;
private MediaPlayerControlsController controller;
private int mediaPlayerID;
/**
* Instantiates a new media player view for solo media player.
*
* @param mediaPath the path of the media to play
* @param mpNumber the id of the media player
*/
public MediaPlayerView(String mediaPath, int mpNumber) {
super();
this.mediaPlayerID = mpNumber;
setLayout(new BorderLayout());
canvas = new Canvas();
canvas.setBackground(Color.BLACK);
canvas.setMinimumSize(new Dimension(600, 250));
this.add(canvas, BorderLayout.CENTER);
controls = new MediaPlayerControls();
controller = new MediaPlayerControlsController(controls, mediaPath, mpNumber, this);
controls.addListeners(controller);
this.add(controls, BorderLayout.PAGE_END);
String name = "Controller" + Integer.toString(mpNumber);
try {
RemoteController stub = (RemoteController) UnicastRemoteObject
.exportObject(controller, 0);
Registry registry = LocateRegistry.getRegistry(1099);
registry.bind(name, stub);
System.out.println(name + " Server ready");
} catch (Exception ex) {
System.err
.println("Controller Server exception: " + ex.toString());
ex.printStackTrace();
}
}
/**
* Instantiates a new media player view for synchronized media players.
*
* @param controller the MainController
* @param mpNumber the ID of the media player
*/
public MediaPlayerView(MainController controller, int mpNumber) {
super();
this.mediaPlayerID = mpNumber;
setLayout(new BorderLayout());
canvas = new Canvas();
canvas.setBackground(Color.BLACK);
//canvas.setMinimumSize(new Dimension(600, 250));
this.add(canvas, BorderLayout.CENTER);
controls = new MediaPlayerControls(mpNumber);
controller.addControls(controls);
controls.addListeners(controller);
this.add(controls, BorderLayout.PAGE_END);
}
/**
* Gets the canvas id.
*
* @return the canvas id
*/
public long getCanvasId() {
return Native.getComponentID(canvas);
}
/**
* Terminates the JVM of the mediaplayer.
*
* @throws RemoteException the remote exception
*/
public void killMP() throws RemoteException {
controller.killMp();
}
/**
* Gets the current time of the media player.
*
* @return the current time of the media player
* @throws IOException Signals that an I/O exception has occurred.
*/
public long getMpTime() throws IOException {
return controller.getMpTime();
}
/**
* Gets the media player id.
*
* @return the media player id
*/
public int getMediaPlayerID() {
return mediaPlayerID;
}
}