Play Mpg/WMV/etc. until completed, then close .exe -- A bit of help needed por favor

This is a discussion on Play Mpg/WMV/etc. until completed, then close .exe -- A bit of help needed por favor within the C Programming forums, part of the General Programming Boards category; I'm writing a program called the Random Chronological Audio/Video Selection Device. What it will do is select files from certain ...

  1. #1
    Registered User
    Join Date
    May 2009
    Location
    Houston, TX
    Posts
    3

    Play Mpg/WMV/etc. until completed, then close .exe -- A bit of help needed por favor

    I'm writing a program called the Random Chronological Audio/Video Selection Device. What it will do is select files from certain folders in My Documents at random and play them on WMP, just like WMP will do if you set it to random; but on top of that I want to have the files selected also according to the time of the day, so that way I can wake up to Hey Arnold at 7am, be listening to Red Hot Chili Peppers at 12pm, and fall asleep to soothing rain drop music at 9pm. The program plays tracks all day one after another so there isn't a moment in which there isn't some sound coming out of my computer.

    So far I've gotten the program to select random files from any destination and play them continuously, but I have to close WMP manually before the program continues on to the next track. How can I tell my program to close WMP after the track is completed, or how can the next track be selected without having to close WMP? Is there a way to do this just with C or do I have to use some sort of API?

    Thanks in advance
    Last edited by Aeroflot; 05-24-2009 at 05:45 PM.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Aeroflot View Post
    How can I tell my program to close WMP after the track is completed, or how can the next track be selected without having to close WMP? Is there a way to do this just with C or do I have to use some sort of API?
    The answer to this one is probably neither. I am not very familiar with windows (I remember WMP), but if you have a "kill" type command there you could apply that to the relevant instance of WMP.

    Another idea would be to either find an app that accepts a list of tracks in a file to play (there are plenty), or write one yourself, which may not be that hard. Presuming it reads from the file at the end of each song (as opposed to loading the list all at once), you can then just add entries to it. Or, your program could just generate a list in the morning to supply to the media player. That is a very quick and simple thing to write; I've done something similar before -- in fact, that was what got me started programming.

    Best of all would be to find a CLI player -- that is, one that does not require a GUI to run. Then you could just issue a command for each tune, eg "mediaplayer somesong.wav".

    Neat idea, by the way. Could get trippy
    Last edited by MK27; 05-24-2009 at 06:21 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    May 2009
    Location
    Houston, TX
    Posts
    3
    I looked up the CLI player and I didn't find one for Windows, but while I was searching I found out that WMP11 has command line support and can open, close, and play from that. It seems as though the problem might be solved. Thanks for the command line idea!

  4. #4
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,174
    Does mplayer not have a Windows port? I'm sure it's sibling, mencoder does.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Quote Originally Posted by MK27 View Post
    The answer to this one is probably neither. I am not very familiar with windows (I remember WMP), but if you have a "kill" type command there you could apply that to the relevant instance of WMP.
    Killing processes is bad. It doesn't give them a chance to clean up.
    Instead, you should send a message to the main window to close (WM_CLOSE).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Elysia View Post
    Killing processes is bad. It doesn't give them a chance to clean up.
    Instead, you should send a message to the main window to close (WM_CLOSE).
    Ah. In unix "kill" could be one of 64 different signals. The default is SIGTERM, which is fine if the process has cleaning up it wants to do atexit(). The more lethal SIGKILL may circumvent that possibility, I'm not sure.

    Anyway, it was the general concept I was referring to. Afterthot: how would you end a process that does not have a window, in windows?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,538
    Ah, Linux is pretty different from Windows.
    If the process has no window and is not a service, then you can only terminate the process. Windows has no other way (and that is a rather poor oversight if you ask me).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,174
    SIGTERM can be caught by the application to allow it to do some cleanup, then exit voluntarily. SIGKILL cannot be caught, and will kill the application immediately and unconditionally.

    I remember seeing, in the shutdown sequence of a few Linux distributions, the system first sends SIGTERM to all processes, and then SIGKILL after a few seconds to kill the remining ones.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,174
    It appears like mplayer DOES have a Windows port.

    MPlayer - The Movie Player

    It's one of the (probably THE) most popular command line media player on Linux. Eats just about all formats under the sun. To run it
    Code:
    mplayer movie.mpg
    .

    It will make a new Window to play the video, and close the window (and kill itself) after the video finishes playing (for audio files, it won't make a window).

  10. #10
    Registered User
    Join Date
    May 2009
    Location
    Houston, TX
    Posts
    3
    The only version of WMP that worked with the open-and-close-after-playing option was 6.4, and that didn't work out. For some reason if WMP stayed open without closing, my program would pause and wait for me to close WMP; but after I added /play /close to the command, my program just opened infinite amounts of WMP windows. So I'm going to try mplayer this time and see how that works.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Gui Class With Tic Tac Toe
    By xxYukoxx in forum C++ Programming
    Replies: 1
    Last Post: 06-01-2003, 04:28 PM
  2. Nibbles (DirectX) play my first completed game's Upgrade!
    By Jeremy G in forum Game Programming
    Replies: 3
    Last Post: 01-25-2003, 06:37 PM
  3. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21