473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

VLC automation

I have pasted the perl script below. Here, I have stored audio files into the mysql database. the "print `vlc "@row"`;" statement launches vlc and starts playing. But it is not quitting after sleeping fot 10 sec. What do i need to do for that?

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. use strict;
  3. no strict "vars";
  4. use warnings;
  5.  
  6. use DBI;
  7. $dbh = DBI->connect('dbi:mysql:audio', 'root', 'ajitteli')
  8.     or die "connection error: $DBI::errstr\n";
  9.  
  10. print "Enter the number of songs to be played:  ";
  11. my $num = <stdin>;
  12.  
  13. for (my $i=1; $i<=$num; $i++) {
  14.     $sql = "select file_path from audio_table where id like $i";
  15.     $sth = $dbh->prepare($sql);
  16.     $sth->execute
  17.         or die "SQL Error: $DBI::errstr\n";
  18.  
  19.     #use IPC::open3;
  20.  
  21.     # my %videoInfo = videoInfo($sth);
  22.  
  23.     # $durtn = $videoInfo{'durationsecs'};
  24.  
  25.  
  26.     while (@row =$sth->fetchrow_array) {
  27.         print "\n\nPlaying song $i\n\n";
  28.  
  29.         print `vlc "@row"`;
  30.         print "song$i stopped\n";
  31.         sleep 10;
  32.  
  33.         print `vlc://quit`;
  34.     }
  35.  
Apr 1 '11 #1
4 2967
Here vlc://quit is not working. What do i need to for quitting vlc through perl?

Expand|Select|Wrap|Line Numbers
  1. #!usr/bin/perl
  2. use strict;
  3. no strict "vars";
  4. use warnings;
  5.  
  6. use DBI;
  7. $dbh = DBI->connect('dbi:mysql:audio', 'root', 'ajitteli')
  8.     or die "connection error: $DBI::errstr\n";
  9.  
  10. print "Enter the number of songs to be played:  ";
  11. my $num = <stdin>;
  12.  
  13. for (my $i=1; $i<=$num; $i++) {
  14.     $sql = "select file_path from audio_table where id like $i";
  15.     $sth = $dbh->prepare($sql);
  16.     $sth->execute
  17.         or die "SQL Error: $DBI::errstr\n";
  18.  
  19.     while (@row =$sth->fetchrow_array) {
  20.         print "\n\nPlaying song $i\n\n";
  21.  
  22.         print `vlc "@row"`;
  23.  
  24.         print "song$i stopped\n";
  25.         sleep 10;
  26.  
  27.         print `vlc://quit`;
  28.     }
  29.  
Apr 1 '11 #2
miller
1,089 Expert 1GB
I do not believe that you understand the nature of backticks ``. Read perlop, search for "qx/STRING/".

Backticks execute an external program but they will wait until it's done before returning the results. If you want to execute vlc.exe and not wait for it to end, you'll have to fork like the following

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Cwd qw(chdir);
  4.  
  5. use strict;
  6. use warnings;
  7.  
  8. my $dir = q{C:\Program Files\VideoLAN\VLC};
  9. my $vlc = q{vlc.exe};
  10. my $mp3 = q{C:\Dropbox\devel\intro.mp3};
  11.  
  12. chdir($dir);
  13.  
  14. my $pid = fork();
  15.  
  16. if (not defined $pid) {
  17.     warn "resources not avilable.\n";
  18.  
  19. } elsif ($pid == 0) {
  20.     exec $vlc, $mp3;
  21.     exit(0);
  22. }
  23.  
  24. sleep 10;
  25.  
  26. # attempt to kill vlc
  27.  
  28. waitpid($pid,0);
  29.  
  30. 1;
  31.  
  32. __END__
  33.  
Now how to kill vlc, I don't know. You'll have to determine the process id of it somehow and send the kill request.

- Miller
Apr 3 '11 #3
miller
1,089 Expert 1GB
Here is how you would kill each vlc instance on windows:

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Cwd qw(chdir);
  4. use Win32::Process::List;
  5.  
  6. use strict;
  7. use warnings;
  8.  
  9. my $dir = q{C:\Program Files\VideoLAN\VLC};
  10. my $vlc = q{vlc.exe};
  11. my $mp3 = q{C:\Dropbox\devel\intro.mp3};
  12.  
  13. chdir($dir);
  14.  
  15. my $pid = fork();
  16.  
  17. if (not defined $pid) {
  18.     warn "resources not avilable.\n";
  19.  
  20. } elsif ($pid == 0) {
  21.     exec $vlc, $mp3;
  22.     exit(0);
  23. }
  24. END {
  25.     waitpid($pid, 0);
  26. }
  27.  
  28.  
  29. for (1..5) {
  30.     print "Hello $_\n";
  31.     sleep 1;
  32. }
  33.  
  34. my $P = Win32::Process::List->new();
  35. my %list = $P->GetProcesses();
  36. if (my @vlc_pids = grep {$list{$_} eq $vlc} keys %list) {
  37.     print "@vlc_pids\n";
  38.     kill 9, $_ for (@vlc_pids);
  39. }
  40.  
Apr 4 '11 #4
RonB
589 Expert Mod 512MB
I'd use Win32::Process which provides methods for creating, suspending, and killing to name a few.

I don't have time to write an example, but the documentation is pretty clear.

http://search.cpan.org/~jdb/Win32-Pr....14/Process.pm
Apr 4 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: SiuLoBow | last post by:
Hi, Is there anyway to detect the ActiveX control is able to run on the browser or not? After I installed the ActiveX control to my system, user sometimes switch the secruity setting to "not...
6
by: ALthePal | last post by:
Hi, I'm not sure if we are able to or even how to loop through the web forms in a VB.NET project during design time. In MSAccess we are able to go through the database -> forms collection and...
3
by: muttu2244 | last post by:
Hi all, Am trying to read a email ids which will be in the form of links ( on which if we click, they will redirect to outlook with their respective email ids). And these links are in the...
0
by: anuradha.k.r | last post by:
HI, I have created a database in MS access97.Also i have a program which would access the database and get me the required record and data.Later I upgraded to MS access 2000.Now I have two...
5
by: Rod | last post by:
About two weeks ago I had an accident and have broken my left elbow and left wrist. For doing things like Word or e-mail (I use Outlook for) I have been using Microsoft's speech recognition and...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
2
by: Rod | last post by:
I have a requirement in which I need to allow the user to log into our ASP.NET application, but also be able to change their Windows password, if it is expired. I had thought that Windows...
3
by: Dhananjayan | last post by:
Hi, I have a java webservice running on Axis, Iam able to create a java client to invoke the webservice and obtain the result. But iam not able to invoke the service from .Net client.. Here are...
3
by: teedilo | last post by:
Our MS SQL (SQL Server 2000) DBA has database privileges locked down pretty tightly. We end users/developers do not have administrator privileges for most databases. That arrangement has worked...
3
by: Aruna1234 | last post by:
Hi , I have laptop through which am able to connect to the tataindicom broadband. But when i use the same laptop to connect to dataone broadband, am not able to view the webpages. when i connect...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.