Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 23, 2017 6:47 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat Mar 06, 2010 10:43 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
All of the following work "as is" with MS WIndows, but may need to be modified to work with the Mac.

MOVIE PLAYER:

Start a new Project, add a MoviePlayer to Window1, and add a "FileOpen" menu item to the File menu, using this code for "FileOpen":

Dim MovieTypes As New FileType
MovieTypes.Name = "Movie files"
MovieTypes.Extensions = ".mpeg; .mpg; .mp4; .wmv"
Dim File1 As FolderItem = GetOpenFolderItem(MovieTypes)
If File1 <> Nil Then
MoviePlayer1.Movie = File1.OpenAsMovie
MsgBox "Double-click movie for full screen;" + EndOfLine + "double-click again to return."
End If
MoviePlayer1.Play

MP3 PLAYER:

Start a new Project, add a MoviePlayer to Window1, and add a "FileOpen" menu item to the File menu, using this code for "FileOpen":

Dim MP3Types As New FileType
MP3Types.Name = "MP3 files"
MP3Types.Extensions = ".mp3"
Dim File1 As FolderItem = GetOpenFolderItem(MP3Types)
If File1 <> Nil Then
MoviePlayer1.Movie = File1.OpenAsMovie
End If
MoviePlayer1.Play

PICTURE VIEWER:

Start a new Project, add an ImageWell to Window1, and add a "FileOpen" menu item to the File menu, using this code for "FileOpen":

Dim PictureTypes As New FileType
Dim Picture1 As Picture
PictureTypes.Name = "Picture files"
PictureTypes.Extensions = ".jpeg; .jpg; .gif; .bmp; .pct; .png"
Dim File1 As FolderItem = GetOpenFolderItem(PictureTypes)
If File1 <> Nil Then
ImageWell1.Image = File1.OpenAsPicture
End If

Suggested improvements or corrections are welcome.

Barry Traver


Last edited by barrytraver on Tue Jan 15, 2013 4:47 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat Mar 06, 2010 11:38 am 
Offline
User avatar

Joined: Fri Sep 30, 2005 11:48 am
Posts: 3554
Location: Lenexa, KS
Couple of things that might be gotchya's:

You don't have any error protection on the folderitem OpenAs functions. You're assuming that each one is valid but they will return nil if they fail for any reason. You might want to check for nil before attempting to assign the movie/music/picture to the control. Nil object exception errors might occur.

You also might want to check if File1.Exists before attempting to open it. It's a nit-pick but if the user selects it in the Open Dialog, goes to the file system and deletes it, you could have a potential error.

If you don't load anything into the movie player, do you really want to play it? Why not simply return? If you run this twice and the second time the user cancels the dialog it will play the first movie/music file again. If that's what you want, that's okay, otherwise it's unexpected behavior.

Paranoia. It's a good thing. :)

_________________
Bob K.

A blog about being a Real Studio/Xojo developer at http://www.bkeeneybriefs.com


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat Mar 06, 2010 1:24 pm 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Bob,

Thanks for the helpful comments. I knew that my code was "bare-bones," so I realized that I was probably missing something (and maybe something important), but thanks to you, I know what that "something" is. (I do expect to expand his "bare-bones" code in other programs, and you're right -- error-handling should be a priority.)

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Fri Mar 19, 2010 8:48 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
I just wanted to clarify the purpose of my "10 lines or less" "Really Basic" programs.

The purpose is NOT to present full-scale programs including all enhancements, error-checking, etc., but to present very brief "bare-bones" programs that do something useful and can be expanded or enhanced as desired. (This seems to be the way it's done with many examples in the RB Language Reference, which often omit any attempt to include full error-checking.)

I am a great believer in concrete examples. As Seneca (the younger) said, "Longum iter est per praecepta, breve et efficax per exempla" (i.e., [Learning] by precept is a long road, but short and beneficial is the way by example)."

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Tue Apr 27, 2010 10:04 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Here's another brief no frills "Really Basic Player" in "9 or 10 Lines of Source," in this case, to (dis)play a text file.

TEXT DISPLAYER

Start a new Project, and put a PushButton control and TextArea control on it. Give the following code to PushButton1.Action:

Dim TextTypes As New FileType
TextTypes.Name = "Text files"
TextTypes.Extensions = ".txt"
Dim FileStreamA As TextInputStream
Dim File1 As FolderItem = GetOpenFolderItem(TextTypes)
If File1 <> Nil Then
FileStreamA = File1.OpenAsTextFile
TextArea1.Text = FileStreamA.ReadAll
FileStreamA.Close
End If

Like the MoviePlayer, MP3 Player, and PictureViewer earlier in this thread, (1) TEXT DISPLAYER is a full working program in 10 lines or less of source, and (2) it is a no frills program to which can be added more adequate error checking, etc.

Enjoy!

Barry Traver

P.S. The purpose of this series is to provide brief code for the novice that will actually do something useful. The examples here can then be enhanced as desired or made part of larger programs.


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Tue Apr 27, 2010 11:27 am 
Offline

Joined: Fri Sep 30, 2005 9:16 am
Posts: 761
barrytraver wrote:
(This seems to be the way it's done with many examples in the RB Language Reference, which often omit any attempt to include full error-checking.)


True. But as useful as the LR is, it misses important opportunities to introduce some good yet simple programming habits that would fall right in line with your stated goals.


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat May 15, 2010 3:06 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
PLAINTEXTSAVER:

Here's another "10 lines or less" utility.

Start a new Project, and put a PushButton control and TextArea control on it. Give the following code to PushButton1.Action:

Dim TextTypes As New FileType
TextTypes.Name = "Text files"
TextTypes.Extensions = ".txt"
Dim FileStreamA as TextOutputStream
Dim File1 As FolderItem = GetSaveFolderItem(TextTypes, "")
if File1 <> Nil then
FileStreamA = TextOutputStream.Create ( File1)
FileStreamA.Write TextArea1.Text
FileStreamA.Close
End if

Then type something into TextArea1 and click on PushButton1. Name your file and save the text!

The preceding code is "homemade" (I didn't see anything exactly like it in the Language Reference or elsewhere), so please let me know if there are any errors (other than the lack of error-checking). Thanks!

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat May 15, 2010 3:20 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Here's a one-liner:

WEBPAGEDISPLAYER:

Start a new Project, and put a PushButton control, a TextField control, and a HTMLViewer control on it. Give the following code to PushButton1.Action:

HTMLViewer1.LoadURL TextField1.Text

Run the program, put a URL (such as http://forums.realsoftware.com or forums.realsoftware.com) into TextField1, and click on PushButton1. That's all there is to it!

Barry Traver


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat May 15, 2010 3:50 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
And here's another short one:

HTMLFILEDISPLAYER:

Start a new Project, and put a PushButton control and HTMLViewer control on it. Give the following code to PushButton1.Action:

Dim HTMLTypes As New FileType
HTMLTypes.Name = "HTML files"
HTMLTypes.Extensions = ".htm; html"
Dim File1 As FolderItem = GetOpenFolderItem(HTMLTypes)
If File1 <> Nil Then
HTMLViewer1.LoadPage File1
End If

HTMLPAGEDISPLAYER:

If you have the HTML information loaded into a TextArea (such as TextArea1), the following should be sufficient:

Dim Fiile1 As New FolderItem
HTMLViewer1.LoadPage ( TextArea1.Text, File1 )

Enjoy!

Barry Traver

P.S. The primary purpose of these short programs is NOT to teach anything to experienced programmers, but to serve as usable learning examples for those who are just beginning their study of REALbasic. (I myself have found these short examples helpful, but I do not regard myself as an experienced or professional programmer.) The code examples are short, but they all have the virtue of serving as fully working programs in themselves (and can be expanded to be parts of longer, more complex programs).


Last edited by barrytraver on Sat Feb 16, 2013 10:18 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Tue May 25, 2010 12:46 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
This example is so simple that I'm reluctant to post it, but it's another example of a program of "9 or 10 lines" or less that can actually do something useful "as is" and may be helpful to the novice programmer as a stepping stone to more complicated programs.

LAUNCHER:

Start a new Project and add a "FileOpen" menu item to the File menu, using this code for "FileOpen":

Dim File1 As FolderItem = GetOpenFolderItem("")
If File1 <> Nil Then
File1.Launch
End If

Instead of "GetOPenFolderItem," of course, you can make reference to a specific file. If the file is an .html file, say, the file will be loaded into the user's default Web browser program (e.g., Mozilla Firefox). If the file is a .txt file, it will be loaded into Notepad or whatever the user's default text editor may be. And so on.

Barry Traver


Last edited by barrytraver on Tue Jan 15, 2013 4:48 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Tue Sep 25, 2012 8:00 pm 
Offline

Joined: Tue Mar 20, 2012 5:45 pm
Posts: 19
How can I make a movie play in full screen mode on various machine, I use real studio on a mac and it is a mac only app.

Tks

Serge


Top
 Profile  
Reply with quote  
 Post subject: Re: Really Basic Players: 9 or 10 Lines of Source Each
PostPosted: Sat Jan 19, 2013 7:41 am 
Offline

Joined: Fri Sep 30, 2005 1:53 pm
Posts: 914
Location: Philadelphia, PA
Some of the earlier code in this thread has been repaired. The repair involved removal of unnecessary "Return True." That was an error of mine, which I didn't notice at the time. No one else commented on it, presumably because the code still worked back then (it was an error tolerated by REALbasic at the time).

REALbasic is now less tolerant of that error. Consequently, I have edited the posts, removing the unnecessary (and now definitely unwanted) "Return True." The code in previous posts in this thread should now work for everyone (including me!).

Barry Traver

P..S. to Serge. I know little about the Mac other than (and I'm not even sure about this) for playing videos the Mac uses QuickTime, while Windows uses the Microsoft Media Player.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group