Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

Need help with accessing data

Discussion in 'Delphi Help&Requests' started by Seabottom, Oct 22, 2014.

  1. Seabottom
    Offline

    Seabottom DF Member

    What I want is simple in theory.

    There's a combo-box with a list.

    When I select an entry on the list and press a button afterwards, I want a video file to be played that correlates to the entry selected. This means that I do no want a pop-up dialog box to choose my file, but the combo-box to choose the file. 

    The files shall be hard-coded into the app to avoid directory issues and also because the app would be useless without those specific video files.

    Is there an easy way to this? I think I tried all of the TOpenDialog function but I might've missed something. Maybe I need something entirely different?

    I got the video playing as I want it, just the data access is the problem.

    [​IMG]
     
  2. John_Smith
    Offline

    John_Smith DF Junior

    What do you mean "The files shall be hard-coded into the app" ?? If you have OpenDialog then its simple :

     if opendialog1.execute then  begin
     MediaPlayer1.FileName := Opendialog1.filename;
     mediaplayer1.Open;

    Better option is to use a database with something like this :

    procedure TForm1.ABSTable1AfterScroll(DataSet: TDataSet);
    var
    Path,S:string;
    begin
    Path := ExtractFilePath(Application.ExeName);
    S := Path + '\Music\' + ABSTable1.FieldByName('Song').AsString;
    if FileExists(S) then
      begin
      MediaPlayer1.FileName:=S;
      MediaPlayer1.Play;
      end else showmessage('no such file');
      end;

    this is from the head...I havent used mediaplayer for a very looong time...
     
  3. AtoZ
    Offline

    AtoZ DF Member

    I guess,

    procedure TForm1.Button6Click(Sender: TObject);
    var
     FileName : string;
    begin

     case ComboBox1.ItemIndex of
     0: FileName := 'Mydir/Media0.caf';
     1: FileName := 'MyDir/Media1.caf';
     else
      FileName := 'MyDir/DeafultMedia.caf';
     end;
      try
       MediaPlayer1.FileName:=FileName;
       MediaPlayer1.Play;
      except
      ShowMessage('Ops,Something wrong.');
      end;
    end;
     
  4. rd3568
    Online

    rd3568 Guest

    Hello,

    What you want to do, is a resource file.  About.com Delphi's section has a pretty informational section on resource files and their usage. Here is the link: http://delphi.about.com/od/objectpascalide/a/embed_resources.htm

     Once you build the resource file, use the listbox/combobox to select the file within the resource.  The basics is similar to the following.  I haven't tested it and it needs to be altered to fit your exact desire.
    [font=Verdana, Arial, Helvetica, sans-serif]procedure TForm1.Button2Click(Sender: TObject);
    var
    rStream: TResourceStream;
    fStream: TFileStream;
    myVideo: string;
    begin {this part extracts the mp3 from exe}
    myVideo := listbox1.items.strings[listbox1.itemindex];
    rStream := TResourceStream.Create(hInstance, 'Intro', RT_RCDATA) ;
    try
    fStream := TFileStream.Create(myVideo, fmCreate) ;
    try
    fStream.CopyFrom(rStream, 0) ;
    finally
    fStream.Free;
    end;
    finally
    rStream.Free;
    end;

    {this part plays the video}
    MediaPlayer1.Close;
    MediaPlayer1.FileName:=myVideo;
    MediaPlayer1.Open;
    end;[/font]


    Remember what files that you place in the resource file will become part of the application. If the the multimedia collection is large, the application will be equally large.  Just a heads up.

    RD
     
  5. Seabottom
    Offline

    Seabottom DF Member

    That's a lot of different possible solutions. I will let you know when I get the correct one :)
     
  6. John_Smith
    Offline

    John_Smith DF Junior

    And when you add a song ? Are you going to recompile resource file every time you add a song ? Not likely.... The best thing is to put all the songs in one folder and access them by their file names. Using a database is the best solution.
     
  7. rd3568
    Online

    rd3568 Guest

    John,
    I agree with the idea of a file look-up table in either a database or configuration file is by far the better choice.  A resource file will be recompiled every time a file is added or removed. To make a completely stand alone application that would not be need to be changed, the resource is the better path. 

    I have created several sound applications for simulators that I just gave them the application and I didn't need to worry about any directory structure. Just a shortcut to the executable.

    There are many choices. That's what makes software development fun.

    Take care,
    RD
     
  8. Seabottom
    Offline

    Seabottom DF Member

    I am going to get long grey hairs before this will be finished I think....

    You guys are right in that I want to be able to add new files with minimal changes to the program. Ideally, adding a video file to the app folder would make it appear on the combobox immediately.

    I want the app to be used on my android phone FYI. That's why I put in the Label1 so that I can see which directory it uses. However all I get is a dash: /. It displays the path name fine if emulated on windows though.

    Same with playing the video; It works fine on windows, but the files doesn't transfer to phone (currently located in debug folder). Where should I put them? Add them to a .jar file in libraries in Project Manager?

    Also, the program HIDE-THANKSs up whenever I press the button saying "begin". I can understand if the MediaPlayerControl is preventing me from using the buttons, however, MediaPlayerControl should not be active when using Index0 of Combobox.
    I suppose this is because there are too many IF-statements in a row, however I can't add any ELSE's without getting an error for some reason.

    I also need a way to make the MediaPlayerControl1 invisible after the video has ended to use the buttons. I think I want to use the back button on the phone for that, though it seems I can't just write the below to do it, something else has to be done.

    procedure vkhardwareback (sender: TObject);
    begin
        Mediaplayercontrol1.Visible := false;
        Key := 0;
    end; 

    It really is a simple app I want, but I guess computer logic =/= human logic.
    I tried all your answers and edited lines here and there, but kept getting errors, so I got the below code for now.

    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    
    var
      S : String;
    
    begin
      getdir(0,S);
      Label1.Text := S; {Display path on top of the app}
    
    if Combobox1.Itemindex=0 then
       Panel1.Visible:=true {Display pop-up box}
    
       else
    
       if  Combobox1.Itemindex=1 then
    
        MediaPlayer1.FileName := S + '\video1.avi';
        Mediaplayercontrol1.Visible := true; {this is aligned to client for full-screen}
        MediaPlayer1.Play;
    
    
       if  Combobox1.Itemindex=2 then
    
        MediaPlayer1.FileName := S + '\video2.avi';
        Mediaplayercontrol1.Visible := true;
        MediaPlayer1.Play;
    
    end;
    
    
    procedure TForm1.Button2Click(Sender: TObject);
    begin
       Panel1.Visible:=false; {Hide pop-up box}
    end;
    
    
    end.
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block