Running VLC player with java - java

I need to open a video in the VLC Player with Java. I have created this program but I don't know how to run a video with this pre-existing code, what should I add in it?
Currently I am using:
package vlc.player;
import java.io.*;
public class vlc
{
public static void main(String[] args) throws IOException,
InterruptedException
{
Runtime.getRuntime().exec("\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\"");
System.out.println("VLC started.");
}
}

Reading the doc you can start VLC with an embedded HTTP server: https://wiki.videolan.org/Documentation:Advanced_Use_of_VLC/#The_HTTP_interface
And the send HTTP requests to perform some operations:
https://wiki.videolan.org/VLC_HTTP_requests/
If you only want to play a file once, just start it as
vlc.exe file://c:\\path\\file.avi

package vlc.player;
import java.io.*;
public class vlc {
public static void main(String[] args)
throws IOException, InterruptedException
{
String [] s= new String[]
{"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe","D:\\Video\\3G\\K.MP4"};
Runtime.getRuntime().exec(s);
System.out.println("VLC started."+"prashant.ibmce#gmail.com");
}
}

Related

How to send outlook mail from java program , without using SMTP

Thanks in advance for your help and support.
Using the below code i am able to open my outlook and specifying TO, CC Subject and Mail Body, but i am unable to send the email automatically, Kindly help on this.
package com.emailtrigger;
import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
public class sendMail
{
public static void main(String[] args) throws URISyntaxException
{
String subject="Email Testing through Code";
String body="This is testing purpose";
String cc="AAA#abc.com";
try {
Desktop.getDesktop().mail( new URI( "mailto:abc#ddd.com?subject="+subject+"&cc="+cc+"&body="+body) );
}
catch ( IOException ex )
{
}
}
}
If you will print error then it is : Illegal character in opaque part.
You should not provide space between values.Ref
All values should be URL-encoded (e.g. space becomes %20)
How to URL encode
Your code in above scenario -
public static void main(String[] args) throws URISyntaxException {
String subject="Email%20Testing%20through%20Code";
String body="This%20is%20testing%20purpose";
String cc="AAA#abc.com";
try {
Desktop.getDesktop().mail( new URI( "mailto:abc#ddd.com?subject="+subject+"&cc="+cc+"&body="+body) );
}
catch ( IOException ex ) {
ex.printStackTrace();
}
}

How to load a http .txt file as a Java FileSystem

I am studying for the Java 1.8 OCP exam and I ran across something in the Oracle study guide p.459 where it says you can load a remote URL as a FileSystem object. I tried this and can't get it to work. What is the simplest hello-world style answer to get this working?
import java.net.*;
import java.nio.file.*;
public class FileTest {
public static void main(String[] args) throws URISyntaxException, MalformedURLException {
FileSystem remoteFS = FileSystems.getFileSystem(
new URI("http://www.gutenberg.org/files/55007")
);
Path remotePath = remoteFS.getPath("55007-0.txt");
System.out.println(remotePath.isAbsolute());
}
}
It throws the error:
Exception in thread "main" java.nio.file.ProviderNotFoundException:
Provider "http" not found
at java.nio.file.FileSystems.getFileSystem(FileSystems.java:224)
at qa.test.FileTest.main(FileTest.java:7)
Addendum:
FileSystemProvider.installedProviders() returns
[sun.nio.fs.MacOSXFileSystemProvider#4554617c, com.sun.nio.zipfs.ZipFileSystemProvider#74a14482]

Text to Speech Converter not working

I am trying to do text to speech converter using java code.And i am using freetts.jar to do this.I need to use this in my web application.
import com.sun.speech.freetts.*;
public class convert {
private static final String VOICENAME="kevin";
public static void call(){
Voice voice;
VoiceManager vm=VoiceManager.getInstance();
System.out.println("come");
voice=vm.getVoice(VOICENAME);
voice.allocate();
try{
voice.speak("wellcome to my world");
System.out.println("coming here good");
}
catch(Exception e){
System.out.println(e);
}
}
public static void main(String agrs[]){
call();
}
}
In the above code was not working voice.speak() method was not working .I don't know why.can any one help me to fix this?
And also i need to know how to make the text to voice conversion with own voice .
Thank you
There is no problem with the code. you must have added only freetts.jar to your buildpath. It will give nullpointer exception.
Add all the jars from the lib folder of freetts-1.2.2-bin to your buildpath.
The same code worked for me.
try and tell me.
And for your implementing your own voice: check out these articles
http://www.codeproject.com/Articles/182881/Text-to-Speech?msg=5074134#xx5074134xx
http://www.acapela-group.com/voices/voice-replacement/faq-my-own-voice/
I know i am posting it little late, but this may help someone. I tried the similar, and it worked for me. Please find the code below.
package com.mani.texttospeech;
import java.beans.PropertyVetoException;
import java.util.Locale;
import javax.speech.AudioException;
import javax.speech.Central;
import javax.speech.EngineException;
import javax.speech.EngineStateError;
import javax.speech.synthesis.Synthesizer;
import javax.speech.synthesis.SynthesizerModeDesc;
import javax.speech.synthesis.Voice;
/**
*
* #author Manindar
*/
public class SpeechUtils {
SynthesizerModeDesc desc;
Synthesizer synthesizer;
Voice voice;
public void init(String voiceName) throws EngineException, AudioException, EngineStateError, PropertyVetoException {
if (desc == null) {
System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
desc = new SynthesizerModeDesc(Locale.US);
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
synthesizer = Central.createSynthesizer(desc);
synthesizer.allocate();
synthesizer.resume();
SynthesizerModeDesc smd = (SynthesizerModeDesc) synthesizer.getEngineModeDesc();
Voice[] voices = smd.getVoices();
for (Voice voice1 : voices) {
if (voice1.getName().equals(voiceName)) {
voice = voice1;
break;
}
}
synthesizer.getSynthesizerProperties().setVoice(voice);
}
}
public void terminate() throws EngineException, EngineStateError {
synthesizer.deallocate();
}
public void doSpeak(String speakText) throws EngineException, AudioException, IllegalArgumentException, InterruptedException {
synthesizer.speakPlainText(speakText, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
}
public static void main(String[] args) throws Exception {
SpeechUtils su = new SpeechUtils();
su.init("kevin16");
// su.init("kevin");
// su.init("mbrola_us1");
// su.init("mbrola_us2");
// su.init("mbrola_us3");
// high quality
su.doSpeak("Hi this is Manindar. Welcome to audio world.");
su.terminate();
}
}
And add the below dependencies to your pom.xml file.
<dependencies>
<dependency>
<groupId>net.sf.sociaal</groupId>
<artifactId>freetts</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
Hope this will be helpful.

How to play an mp3 file in java

I am trying to play a song (mp3 file) in java. I have been looking around for a few hours now and none of the ways I found worked properly.
public void play()
{
String song = "song.mp3";
Media track = new Media(song);
MediaPlayer mediaPlayer = new MediaPlayer(track);
mediaPlayer.play();
}
I have tried doing that but it gives me errors.
I have imported JMF and JLayer.
I have also read other questions that are like this one on this forum and none of them have helped me.
I just need a hand to help play an mp3 file.
The easiest way I found was to download the JLayer jar file from http://www.javazoom.net/javalayer/sources.html and to add it to the Jar library http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29
Here is the code for the class
public class SimplePlayer {
public SimplePlayer(){
try{
FileInputStream fis = new FileInputStream("File location.");
Player playMP3 = new Player(fis);
playMP3.play();
}catch(Exception e){System.out.println(e);}
}
}
and here are the imports
import javazoom.jl.player.*;
import java.io.FileInputStream;
For this you'll need to install Java Media Framework (JMF) in your PC. One you have it installed,then try this piece of code:
import javax.media.*;
import java.net.*;
import java.io.*;
import java.util.*;
class AudioPlay
{
public static void main(String args[]) throws Exception
{
// Take the path of the audio file from command line
File f=new File("song.mp3");
// Create a Player object that realizes the audio
final Player p=Manager.createRealizedPlayer(f.toURI().toURL());
// Start the music
p.start();
// Create a Scanner object for taking input from cmd
Scanner s=new Scanner(System.in);
// Read a line and store it in st
String st=s.nextLine();
// If user types 's', stop the audio
if(st.equals("s"))
{
p.stop();
}
}
}
You may run into unable to handle formaterror, that is because Java took out the MP3 support by default (pirate copyright issue), you are required to install a “JMF MP3 plugin” in order to play MP3 file.
Go Java’s JMF website to download it
http://java.sun.com/javase/technologies/desktop/media/jmf/mp3/download.html
To be sure that you are using a supported format file, check here:
http://www.oracle.com/technetwork/java/javase/formats-138492.html
If you are using windows7, you may have to read this as well:
https://forums.oracle.com/forums/thread.jspa?threadID=2132405&tstart=45
How about JavaFX application-
import java.net.URL;
import javafx.application.Application;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
public class VLC extends Application {
void playMedia() {
String mp3 = "00- Tu Hi Mera.mp3";
URL resource = getClass().getResource(mp3);
System.out.println(resource.toString());
Media media = new Media(resource.toString());
MediaPlayer mediaPlayer = new MediaPlayer(media);
mediaPlayer.play();
}
public static void main(String args[]) {
new VLC().playMedia();
}
#Override
public void start(Stage stage) throws Exception {
}
}

Crystal report SDK JRC Passing parameter giving error Error code:-2147217394 Error code name:missingParameterValueError

When I am trying pass paramaters from crystal report SDK and export my report to PDF. It is stand alone application so I can't user crystalreportviewer options but it is keep giving me error
com.crystaldecisions.sdk.occa.report.lib.ReportSDKParameterFieldException: InternalFormatterException---- Error code:-2147217394 Error code name:missingParameterValueError My code is given below please help
import com.crystaldecisions.reports.sdk.DatabaseController;
import com.crystaldecisions.reports.sdk.ReportClientDocument;
import com.crystaldecisions.reports.sdk.ParameterFieldController;
import com.crystaldecisions.sdk.occa.report.data.IConnectionInfo;
import com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
public class Test {
public static void main(String args[]) throws ReportSDKException, SQLException, FileNotFoundException, IOException{
try{
ReportClientDocument reportClientDoc = new ReportClientDocument();
reportClientDoc.open("Report.rpt",0);
ParameterFieldController paramController = reportClientDoc.getDataDefController().getParameterFieldController();
paramController.setCurrentValue("","P_DP",new Integer(22));
//Here I was calling switch database code
ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getReportSource().export(ReportExportFormat.PDF);
IOUtils.copy(byteArrayInputStream, new FileOutputStream("new.pdf"));
reportClientDoc.close();
}
}
it starts working by just moving setting parameter code to above line. we need to set parameter before opening the report.
import com.crystaldecisions.reports.sdk.DatabaseController;
import com.crystaldecisions.reports.sdk.ReportClientDocument;
import com.crystaldecisions.reports.sdk.ParameterFieldController;
import com.crystaldecisions.sdk.occa.report.data.IConnectionInfo;
import com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
import com.crystaldecisions.sdk.occa.report.lib.ReportSDKException;
public class Test {
public static void main(String args[]) throws ReportSDKException, SQLException, FileNotFoundException, IOException{
try{
ReportClientDocument reportClientDoc = new ReportClientDocument();
ParameterFieldController paramController = reportClientDoc.getDataDefController().getParameterFieldController();
paramController.setCurrentValue("","P_DP",new Integer(22));
reportClientDoc.open("Report.rpt",0);
//Here I was calling switch database code
ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream)reportClientDoc.getReportSource().export(ReportExportFormat.PDF);
IOUtils.copy(byteArrayInputStream, new FileOutputStream("new.pdf"));
reportClientDoc.close();
}
}

Categories