Posted: Thu Jun 22, 2006 4:23 pm Post subject: Media Player Help
Ok, here is a media player I'm making so it doesn't hog up as much power as Windows Media Player. But I'm having one small problem. I'm using setscreen("text"), and I was wondering how do I locate when I ask the user to enter a song back in the same position in "Selective mode", so I can remove the "Press Any Key To Exit, and just have the "Play which song" looping in 1 spot, and maybe have a press q to quit thing., so the user can switch tracks.
PS: It's still in proggress, I will make it more fancy maybe later on and add buttons or something.
code:
%MEDIA PLAYER
loop
var winID := Window.Open ("graphics:0;0")
var dir, song : string
var cnt := 0
dir := "C:/Documents and Settings/" + Sys.GetUserName + "/My Documents/My Music/"
setscreen ("text")
var streamNumber := Dir.Open (dir)
var num : int
var choice : char
var fileName : string
put "1 - Sequential"
put "2 - Selective"
loop
choice := getchar
exit when choice not= ""
end loop
put ""
for i : 1 .. streamNumber
fileName := Dir.Get (streamNumber)
exit when fileName = ""
if fileName (length (fileName)) = "3" then
cnt += 1
put cnt, ". ", fileName
if (choice = '1') then
Music.PlayFileReturn (dir + fileName)
Input.Pause
Music.PlayFileStop
end if
end if
end for
Dir.Close (streamNumber)
put ""
put "Play which song? " ..
get song : *
Music.PlayFileReturn (dir + song + ".mp3")
put ""
put "Press any key to exit " ..
Input.Pause
Music.PlayFileStop
Window.Close (winID)
return
end loop
Sponsor Sponsor
Guest
Posted: Thu Jun 22, 2006 4:34 pm Post subject: (No subject)
Also, how would I locate so I can remove the .mp3 when I display the files in "Sequential and Selective" modes. Times like this I wish there was an edit button... Cause I had to delete my first post and this post once each to edit them.
aldreneo
Posted: Thu Jun 22, 2006 6:48 pm Post subject: (No subject)
Sorry, don't have an answer for you....But I agree this section of the forums needs an edit button...You would not beleve how many times I see someone correct a problem with his or her code
such as something like this:
code:
put "hi""
or
code:
print "hi"
or
code:
var cow:string;
get cow;
put cow;
or
code:
put ('Hi');
Delos
Posted: Thu Jun 22, 2006 7:02 pm Post subject: (No subject)
If you mean using locate() as in:
code:
locate (1, 1)
put "Hello world"
then I'm afraid that won't work in text-mode. There's a reason why it's called that ! Locate's are essentially a graphical manipulation of the screen, hence you have to do them in graphics mode. I don't see any problem with using graphics-mode over pure-text, since it offers your that flexibility while maintaining the minimalistic style of text-only.
@Edit button question - and just as many times as you've seen such questions, we've heard this same question. The answer is simple - not likely. It was removed a while ago for reasons of wanton abuse. That's pretty much all there is to it...but of course there still is that ever-useful Preview button whose use would somewhat diminish the need of an Edit button...
Dan
Posted: Thu Jun 22, 2006 7:24 pm Post subject: Re: Media Player Help
vahnx wrote:
Ok, here is a media player I'm making so it doesn't hog up as much power as Windows Media Player.
Sorry to break it to you but a "hello world" program in turing with a loop of any kind that dose not exit right away will take up as much if not more power then windows media player cpu wise. Memeory wise it might be close but turing loads alot of undeed things, esptaly when made in to an exe.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Clayton
Posted: Thu Jun 22, 2006 8:35 pm Post subject: (No subject)
@Delos: it most certainly does
code:
View.Set ("text")
locate (1,1)
put "Hello World"
will output Hello World at the top left hand corner of the screen. I think you are thinking of locatexy, which locates in pixels, not columns and rows, which is what text mode uses , one character takes up one row and one column (ie. "L" at (1,1) will take up column 1 and row 1), in text mode instead of using maxx and maxy you use maxrow, and maxcol
Delos
Posted: Thu Jun 22, 2006 9:13 pm Post subject: (No subject)
Curious.
This does not work:
code:
View.Set ("text")
put "Hello"
locate (2, 1)
put "World"
And neither does your code. You'd better double check to make sure. It crashes with:
Error.LastMsg wrote:
Output from "Text.Locate" cannot be sent to a text window.
Clayton
Posted: Thu Jun 22, 2006 9:54 pm Post subject: (No subject)
hm, that is weird, it works on my computer, i dont know why it wouldnt on yours, good luck finding out why
Sponsor Sponsor
Guest
Posted: Thu Jun 22, 2006 10:39 pm Post subject: (No subject)
=(, Maybe instead of text I could use graphics... I will needa find out how to scroll tho, using the scrolly commandy thingy, whatever.
Delos
Posted: Fri Jun 23, 2006 9:13 am Post subject: (No subject)
SuperFreak82 wrote:
hm, that is weird, it works on my computer, i dont know why it wouldnt on yours, good luck finding out why
Though it should make no difference, what version of Turing are you running?
Guest
Posted: Fri Jun 23, 2006 11:44 am Post subject: Back To My Media Player...
Ok, here is my Media Player So Far. I was wondering, how exactly do I scroll? I'm new to this GUI.Scroll thing, and I'm trying to use the increments, but the Help menu doesn't give me an example of GUI.**ScrollButtonFull.
Also, after I'm done scrolling, how would I allow the user to still Input, then if they don't want an Input, they can still scroll without having to enter an Input. Because once I have my Input statement, it doesn't allow me to scroll because it's waiting for an input.
code:
%MEDIA PLAYER
import GUI
var window1 := Window.Open ("graphics:1000;600,nobuttonbar")
var dir, song : string
var cnt := 0
dir := "C:/Documents and Settings/" + Sys.GetUserName + "/My Documents/My Music/"
var streamNumber := Dir.Open (dir)
var scrollBar : int
var num : int
var choice : char
var fileName : string
put "Hello ", Sys.GetUserName, " on ", Sys.GetComputerName
put ""
put "1 - Sequential (any key for next song)"
put "2 - Selective (type in name of song)"
loop
choice := getchar
exit when choice not= ""
end loop
put ""
for i : 1 .. streamNumber
fileName := Dir.Get (streamNumber)
exit when fileName = ""
if fileName (length (fileName)) = "3" then
cnt += 1
put cnt, ". ", fileName
if (choice = '1') then
Music.PlayFileReturn (dir + fileName)
Input.Pause
Music.PlayFileStop
end if
end if
end for
Dir.Close (streamNumber)
procedure Scrolling (value : int)
locate (20, 50)
put value : 3
GUI.Refresh
end Scrolling
put ""
GUI.Refresh
loop
% put "Play which song? " ..
% get song : *
% Music.PlayFileReturn (dir + song + ".mp3")
% if File.Exists (dir + song + ".mp3") then
% put "Currently playing '", song, "'. " ..
% else
% put "File does not exist! " ..
% end if
% put "Press any key for next song..."
% Input.Pause
% locate (maxrow - 2, 1)
% put ""
% locate (maxrow - 2, 1)
% Music.PlayFileStop
exit when GUI.ProcessEvent
end loop
Delos
Posted: Fri Jun 23, 2006 12:26 pm Post subject: (No subject)
GUI scrolling must be done with GUI objects. Right now, you're working with text objects. I'm afraid you can't have both - you have to choose. Either the minimalistic and functional advantage of text, or the prettiness and brain-busting of GUI.
If you do decide to go for the latter, my advice to you is not to use the Turing GUI. You are a competent enough programmer to create your own GUI - in fact, this will essentially allow you to get as close to the above mentioned compromise as possible. Creating a scroll box won't be too difficult, as far as such things go. Simply have a flexy array of each line, and some mouse-activated arrows that allow you to determine which lines are displayed.
As a related aside - one of the primary reasons why I discourage Turing GUI use is its own issues with itself. You've likely heard of instances where one programme causes another to have a hissie fit, but in Turing's case, one object in the GUI is incompatible with another. I forget exactly which ones were involved, but I think it was a text box and a text field - put them together wrongly and they simply wouldn't work.
These sorts of problems are avoidable if you can recreate your own customizable content. Check out Cervantes' custom text fields if you want a great example of what custom GUI looks like. (AFAIK, the S-Engine isn't custom GUI, it's just the standard one skinned - but I may be wrong).
Guest
Posted: Fri Jun 23, 2006 10:40 pm Post subject: Ok All Good So Far
I was wondering, what's wrong with line 97 of this code. If you remove the Return on Music.PlayFileReturn, it works fine when you type the ID number. Otherwords, it doesn't play the song at all. (The message you get is true because the song you entered was a number if it's Music.PlayFileReturn.) I use mostly text mode.
code:
%MEDIA PLAYER
import GUI
var window0 := Window.Open ("0,0")
var mode : char
put "1-GUI 2-TEXT"
put "Choose A Mode: " ..
loop
exit when (mode = '1') or (mode = '2')
mode := getchar
end loop
Window.Close (window0)
if (mode = '2') then
setscreen ("text")
else
var window1 := Window.Open ("graphics:1000;2000,nobuttonbar")
end if
var dir, song, rename : string
var cnt := 0
dir := "C:/Documents and Settings/" + Sys.GetUserName + "/My Documents/My Music/"
var streamNumber := Dir.Open (dir)
var scrollBar : int
var num : int
var choice : char
var fileName : string
var songID : array 1 .. 200 of string
put "Hello ", Sys.GetUserName, " on ", Sys.GetComputerName, ". Welcome to the Media Player!"
put "Make Sure All Song Files Are In: "
put dir
put "NOTE: Only supports up to approximately 200 songs"
put ""
put "1 - Sequential (any key for next song)"
put "2 - Selective (type in name of song)"
put "3 - Rename Files (allows you to rename any music file)"
loop
choice := getchar
exit when choice not= ""
end loop
put ""
for i : 1 .. streamNumber
fileName := Dir.Get (streamNumber)
exit when fileName = ""
if fileName (length (fileName)) = "3" then
cnt += 1
songID (cnt) := fileName
put cnt, ". ", songID (cnt)
if (choice = '1') then
Music.PlayFileReturn (dir + fileName)
Input.Pause
Music.PlayFileStop
end if
end if
end for
Dir.Close (streamNumber)
procedure Scrolling (value : int)
locate (20, 50)
put value
GUI.Refresh
end Scrolling
procedure Locate
if (mode = '1') then
locate (maxrow - 2, 1)
put ""
locate (maxrow - 2, 1)
else
put ""
end if
end Locate
if (mode = '1') then
scrollBar := GUI.CreateVerticalScrollBarFull (maxx - 50, 50, maxy - 50, 1, cnt, 1, Scrolling, 0, 0, 0)
end if
put ""
GUI.Refresh
loop
if (choice = '2') then
put "Play which song? " ..
elsif (choice = '3') then
put "Rename which song? " ..
end if
get song : *
if (choice = '2') then
for i : 1 .. streamNumber
if strintok (song) then
if strint (song) = i then
Music.PlayFileReturn (dir + songID (i)) %switch
end if
end if
end for
Music.PlayFileReturn (dir + song + ".mp3")
if File.Exists (dir + song + ".mp3") then
put "Currently playing '", song, "'. " ..
else
put "File does not exist! " ..
end if
put "Press any key for next song..."
Input.Pause
Locate
Music.PlayFileStop
elsif (choice = '3') then
if File.Exists (dir + song + ".mp3") then
put "What do you want the song to be renamed to? " ..
get rename : *
File.Rename (dir + song + ".mp3", dir + rename + ".mp3")
else
put "File does not exist!"
end if
Locate
end if
if (mode = '1') then
exit when GUI.ProcessEvent
end if
end loop
Guest
Posted: Fri Jun 23, 2006 10:53 pm Post subject: (No subject)
PS: I need to use PlayFileReturn so you can end the song at any time. Also, Music.PlayFile works fine, except for the fact I want to be able to end the song right away. I don't know why Music.PlayFileReturn would act up like this, could it be a Turing bug?
Guest
Posted: Tue Jul 04, 2006 11:07 pm Post subject: (No subject)
Can anyone help me, it's been over a week and still no help.