Playing Video file using VLCJ library in java

In this we are going to see how to play an video file using vlcj library in java, It is very simple and works great.. Thanks to VLC team.

Now Some Requirements

1 . VLC Media player versionĀ 2.1.5 minimum.

2. VLCJ 3.0.1 can download from

https://code.google.com/p/vlcj/downloads/list

………………………………………………………………………………….

Now create a class and add VLCJ , platform and jna library from VLCJ distribution pack which can download from above link.

CodingĀ :

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;

public class VLCPlayer {

private EmbeddedMediaPlayerComponent mediaPlayerComponent;

//This is the path for libvlc.dll
static String VLCLIBPATH = “C:\\Program Files (x86)\\VideoLAN\\VLC”;
public static void main(String[] args) {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), VLCLIBPATH);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
VLCPlayer vlcPlayer = new VLCPlayer(“Fedora”);
}
});

}
private VLCPlayer() {

//MAXIMIZE TO SCREEN
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

JFrame frame = new JFrame(“VLC Player”);

mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

frame.setContentPane(mediaPlayerComponent);

frame.setLocation(0, 0);
frame.setSize(screenSize.width, screenSize.height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);

mediaPlayerComponent.getMediaPlayer().playMedia(“Movie name”);//Movie name which want to play
}
}

Now compile and run the VLCPlayer.java

you can view the frame opened with playing the video specified

PHP Pagination of Result

Every search result pages need’s pagination (i.e) numbering the result page with limitation. In this post I will explain how to limit the MySQL query and numbering the page’s with page number according to the result page.

Steps :

1 . Query the result with limit included

2. Number the Page count accordingly.

 

Program :

<div>
<?php

mysql_connect(“yourhost”,”username”,”password”);
mysql_select_db(“students_test”);
$rowsPerPage = 10;
$pageNum = $_GET[“pagenum”];
$offset = ($pageNum – 1) * $rowsPerPage;

$sql = ‘select * from comment LIMIT ‘.$offset.’,’. $rowsPerPage;
$query = mysql_query($sql) or die(mysql_error());
echo ‘<table border=1>’;
while($r = mysql_fetch_array($query))
{
echo ‘<tr><td>’;
echo $r[“commentline”];
echo ‘</td></tr>’;
}
echo ‘</table><br>’;

?>
</div>
<?php

//Getting number of rows
mysql_connect(“your_host”,”username”,”password”);
mysql_select_db(“students_test”);
$msql = “select * from comment”;
$mquery = mysql_query($msql) or die(mysql_error());
$dbrows = mysql_num_rows($mquery);
$rows = ($dbrows)/$rowsPerPage;
$rem = $rows%$rowsPerPage;
if($rem!=0)
{
$rows++;
}
echo ‘Total Records : ‘.$dbrows.’ | Pages : ‘.$rows.’ | Rem : ‘.$rem.’ | Current Page : ‘.$pageNum;

?>
<div>
<?php
$plimit = 10;
if($rows <= 10)
{
$plimit = $rows;
}
$start = 1;
$end = $rows;
if($rows >= 1 && $rows <= $plimit)
{
$start = 1;
$end = $plimit;
}
else
{
if($pageNum == $rows)
{
$start = $pageNum-$plimit;
$end = $pageNum;
}
else
{
if($pageNum >= $rows-4 || $pageNum >= $rows-3 || $pageNum >= $rows-2 || $pageNum >= $rows-1)
{
$start = $rows-$plimit;
$end = $rows;
}
else if(($pageNum) <= 5)
{
$start = 1;
$end = $plimit;
}
else
{
$start = $pageNum-5;
$end = $pageNum+4;
}
}
}
for($i=$start;$i<=$end;$i++)
{
echo ‘<a href=”index.php?pagenum=’.$i.'”>’.$i.'</a> ‘;
} ?>
</div>