import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.util.List;
//import java.util.Vector;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.binding.internal.libvlc_media_t;
import uk.co.caprica.vlcj.player.MediaPlayer;
import uk.co.caprica.vlcj.player.MediaPlayerEventAdapter;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import com.sun.jna.NativeLibrary;
import com.sun.jna.Native;
/**
* This class displays the details of a music recording.
* It shows the artist's name, recording title and price.
* Also, the dialog shows an image of the recording along
* with its track list. <p>
*
* Usage Example:
*
* <pre>
*
* MusicDetailsDialog myDetailsDialog = new MusicDetailsDialog(myParentContainer, myRecording);
* myDetailsDialog.setVisible(true);
*
* </pre>
*
* @author Matthew
*/
@SuppressWarnings("serial")
public class GameDetailsDialog extends JDialog {
/**
* A holder for the music recording that is passed in during construction
*/
protected MusicRecording myRecording;
private EmbeddedMediaPlayer mediaPlayer;
private MediaPlayerFactory factory;
/**
* A holder for the parent frame that is passed in during construction
*/
protected Container parentContainer;
boolean lineWrap;
JTextArea ta = new JTextArea(30,30); /**
* Constructs a modal dialog for a given music recording. This version
* uses the artist name and recording title for the dialog title.
*
* @param theParentContainer the parent frame for this dialog
* @param theMusicRecording the music recording to display
*/
public GameDetailsDialog(JFrame theParentContainer, MusicRecording theMusicRecording) {
this(theParentContainer, "Game Information For" + theMusicRecording.toString(), theMusicRecording);
}
/**
* Constructs a modal dialog for a given music recording. This version allows you to customize the title
*
* @param theParentContainer the parent frame for this dialog
* @param theTitle the title of the dialog
* @param theMusicRecording the music recording to display
*/
public GameDetailsDialog(JFrame theParentContainer, String theTitle, MusicRecording theMusicRecording) {
super(theParentContainer, theTitle, true); // creates a modal dialog
myRecording = theMusicRecording;
parentContainer = theParentContainer;
parentContainer.setSize(1000,400);
buildGui();
}
/**
* This method covers the details of creating and arranging the dialog components.
* @throws IOException
*/
private void buildGui(){
setLayout(new BorderLayout());
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
//
// artist info panel
//
final JPanel infoPanel = new JPanel();
infoPanel.setBorder(new EmptyBorder(10, 10, 0, 10));
infoPanel.setLayout(new GridBagLayout());
final GridBagConstraints c = new GridBagConstraints();
// create and arrange the label, "Artist: ..."
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 3;
c.weightx = 0.0;
c.weighty = 0.0;
c.fill = GridBagConstraints.BOTH;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(10, 0, 0, 10);
JLabel artistLabel = new JLabel("Publisher: " + myRecording.getArtist());
infoPanel.add(artistLabel,c);
// create and arrange the label, "Title: ..."
c.gridy = GridBagConstraints.RELATIVE;
c.insets = new Insets(0, 0, 0, 10);
JLabel titleLabel = new JLabel("Title: " + myRecording.getTitle());
infoPanel.add(titleLabel,c);
// create and arrange the label, "Category ..."
//JLabel categoryLabel = new JLabel("Genre: " + myRecording.getCategory());
//c.insets = new Insets(2, 0, 2, 0);
//i//nfoPanel.add(categoryLabel, c);
// create and arrange the label, "Duration..."
// Duration theDuration = myRecording.getRunningTime();
// int runningTime = theDuration.getTotalSeconds() / 60;
// JLabel durationLabel = new JLabel("Duration: " + runningTime + " mins.");
// infoPanel.add(durationLabel, c);
// create and arrange the label, "Price: $..."
c.insets = new Insets(0, 0, 0, 10);
JLabel priceLabel = new JLabel("Year:" + myRecording.getYear());
infoPanel.add(priceLabel,c);
c.insets = new Insets(2,0,0,10);
JLabel boxLabel = new JLabel ("Box:");
infoPanel.add(boxLabel,c);
c.insets = new Insets(0,0,0,0);
JLabel manualLabel = new JLabel ("Manual:");
infoPanel.add(manualLabel,c);
c.insets = new Insets(0,0,0,0);
JLabel extrasLabel = new JLabel ("Extras:");
infoPanel.add(extrasLabel,c);
// create an arrange the recording icon
c.gridx = 3;
c.gridy = 1;
c.gridwidth = GridBagConstraints.REMAINDER;
c.gridheight = 5;
c.fill = GridBagConstraints.NONE;
c.weightx = 1.0;
c.weighty = 1.0;
c.insets = new Insets(5, 5, 20, 0);
String imageName = myRecording.getImageName();
String gameDescr = myRecording.getDescr();
ImageIcon recordingIcon = null;
//String fileName = ("images/descriptions/" + gameDescr);
JLabel recordingLabel = null;
// attempt to load the image
try
{
if (imageName.trim().length() == 0) {
recordingLabel = new JLabel(" Image not available ");
}
else {
recordingIcon = new ImageIcon(getClass().getResource("images/music/" + imageName));
recordingLabel = new JLabel(recordingIcon);
}
}
catch (Exception exc)
{
// okay...couldn't load. Just give a text message.
recordingLabel = new JLabel(" Image not available ");
}
recordingLabel.setBorder(BorderFactory.createRaisedBevelBorder());
//recordingLabel.setToolTipText(myRecording.getArtist());
infoPanel.add(recordingLabel, c);
add(BorderLayout.NORTH, infoPanel);
//
try{
String lines2;
// Populate the list box with the descr from the file.
//File fr = new File("images/descriptions/" + gameDescr);
FileInputStream in = new FileInputStream("images/descriptions/" + gameDescr);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
// Vector<String> lines = new Vector<String>();
// String buffer;
while ((lines2=br.readLine())!=null){
//lines2.add(buffer);
ta.append(lines2 + "\n");
}
// JList trackListBox= new JList(lines);
//allow text to be wrapped
ta.setLineWrap(true);
//ta.setWrapStyleWord(true);
//makes text so that it is not editable
ta.setEditable(false);
//points the scroll cursor to the top of the text area.
ta.setCaretPosition(0);
//ta.setSize(20, 50);
JScrollPane tracksScrollPane = new JScrollPane(ta);
tracksScrollPane.applyComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
tracksScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
tracksScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
TitledBorder listBorder = BorderFactory.createTitledBorder("Description");
tracksScrollPane.setBorder(listBorder);
tracksScrollPane.getViewport().setViewPosition(new Point(0,0));
System.out.println(ta.getSize());
add(BorderLayout.CENTER, tracksScrollPane);
}
catch(Exception e){
e.printStackTrace();
}
// Create and add the "OK" button
JPanel bottomPanel = new JPanel();
JButton okButton = new JButton("OK");
bottomPanel.add(okButton);
add(BorderLayout.SOUTH, bottomPanel);
okButton.addActionListener(new OkButtonActionListener());
//end build gui
NativeLibrary.addSearchPath(
RuntimeUtil.getLibVlcLibraryName(), "C:/Users/mfierro/Desktop/crs471/VideoLAN/VLC"
);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
System.out.println("I am here");
JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setLocation(100, 100);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true);
frame.setVisible(true);
JPanel cp = new JPanel();
// cp.setBackground(Color.BLACK);
cp.setLayout(new BorderLayout());
JPanel ip = new JPanel();
ip.setBorder(new EmptyBorder(4, 4, 4, 4));
ip.setLayout(new BoxLayout(ip, BoxLayout.X_AXIS));
cp.add(ip,BorderLayout.NORTH);
Canvas vs = new Canvas();
vs.setBackground(Color.black);
vs.setVisible(true);
cp.add(vs, BorderLayout.CENTER);
frame.add(cp,BorderLayout.CENTER);
factory = new MediaPlayerFactory();
mediaPlayer = factory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(factory.newVideoSurface(vs));
//mediaPlayer.setVideoSurface(factory.newVideoSurface(eastPanel));
mediaPlayer.setPlaySubItems(true); // <--- This is very important for YouTube media
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter(){
@Override
public void mediaSubItemAdded(MediaPlayer mediaPlayer, libvlc_media_t subItem){
List<String> items = mediaPlayer.subItems();
System.out.println(items);
}
});
String mrl = "http://www.youtube.com/watch?v=AwN_Dpsdnuw";
mediaPlayer.playMedia(mrl);
}
});
// this.pack();
// locate this window based off of the parent frame
Point parentLocation = parentContainer.getLocation();
this.setLocation(parentLocation.x + 50, parentLocation.y + 50);
}
private void exit(int value){
mediaPlayer.stop();
mediaPlayer.release();
factory.release();
System.exit(value);
}
//
// INNER CLASS
//
/*
/**
* Closes the dialog when ok button is pressed
*/
class OkButtonActionListener implements ActionListener {
/**
* Simply closes this dialog.
*/
public void actionPerformed(ActionEvent event)
{
setVisible(false);
}
}
}