25 May '13 - 14:59 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: How to: Play mod files from disc and use mod files from Resource (C#)  (Read 388 times)
DarkTyranno
Guest
« on: 11 Feb '13 - 09:31 »
Reply with quoteQuote

Hey all, I'm working on a small standalone instant run executable that will run and view my .nfo files.
See http://www.codeproject.com/Articles/505994/Creating-a-NFO-Viewer-in-Csharp-as-a-beginner for a picture and source code of this project.

One of the last things I have to figure out is how to use BASS in this project. I've implemented irrKlang before, but it didn't support all tracks I wanted to use.
The demo player of BASS did play those tracks. The source code was for C, so I couldn't open it... -.-
So far I've got this working:

            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            int music = Bass.BASS_StreamCreateFile("lol.mp3", 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_MUSIC_LOOP);
            Bass.BASS_ChannelPlay(music, false);

Problem is: 1) It plays from debug/project folder, I want to use a location on computer, but prefer using the Resource option!
                2) It's .mp3, I want to play mod files (.it, .xm, .mod) which don't even work in the project folder.

So, how do I:
> Play the mod files? Is it the way I load them.. is StreamCreateFile for .mp3 only? MusicLoad didn't work either, what do I need to use?
> Play the mod files from resources, I want to add the mod file as a resource file and then play it from there, so I don't have to sent my mod file with every application and let it play it from a specific location on the computer...

Can anyone help me out with these steps please?
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 11 Feb '13 - 15:39 »
Reply with quoteQuote

Yes, for MOD files you will need to use BASS_MusicLoad instead of BASS_StreamCreateFile (the parameters are much the same - see the documentation for details). To play a resource, you need to get the resource's memory location and size, and then pass that to BASS_MusicLoad. I'm not a .Net user myself, so I'm afraid I can't advise on how it would be done there, but here is an example C/C++ snippet that will hopefully give some idea...

   www.un4seen.com/forum/?topic=12731
Logged
DarkTyranno
Guest
« Reply #2 on: 12 Feb '13 - 11:36 »
Reply with quoteQuote

Yay, I finally got the mod music working.
After all the tasks of importing and referring to the dll's...
I already started with the wrong method.
Here's the code that works from a location on computer:

            Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            int load = Bass.BASS_MusicLoad("C:\\Test\\lol.it", 0, 0, BASSFlag.BASS_SAMPLE_LOOP, 0);
            Bass.BASS_ChannelPlay(load, false);

It really isn't more! But I couldn't just make this up.
I also have my checkbox (Music?) with:

        // This will pause and resume the track if users (un)check the checkbox.
        private void checkBox_CheckedChange(object sender, EventArgs e)
        {
            CheckState state = checkBox.CheckState;
            if (state == CheckState.Checked)
            {
                Bass.BASS_Start();
            }
            else
            {
                Bass.BASS_Pause();
            }
        }

This is a big step for me, now I can test and change the mod player in my applications.
The next step is for me to call the tracks from resource, that will be easier if I have some working code that can play from computer already.
Besides that I also want to add the dll's as resources, so I just have my .exe to share.
I'm going to try this myself again, it isn't directly related to BASS anyway.

Thanks for the help!
Logged
Chris
Posts: 1507


« Reply #3 on: 12 Feb '13 - 19:12 »
Reply with quoteQuote

// This will pause and resume the track if users (un)check the checkbox.
        private void checkBox_CheckedChange(object sender, EventArgs e)
        {
            CheckState state = checkBox.CheckState;
            if (state == CheckState.Checked)
            {
                Bass.BASS_Start();
            }
            else
            {
                Bass.BASS_Pause();
            }
        }

no that should pause bass
this is better

 // This will pause and resume the track if users (un)check the checkbox.
       
private void checkBox_CheckedChange(object sender, EventArgs e)
        {
            CheckState state = checkBox.CheckState;
            if (state == CheckState.Checked)
            {
                BASS_ChannelPlay(load,false);
            }
            else
            {
                BASS_ChannelPause(load);
            }
        }
Logged
DarkTyranno
Guest
« Reply #4 on: 13 Feb '13 - 09:06 »
Reply with quoteQuote

Ohw, you're right.
Well, it doesn't matter in my case, as I use one track at a time (only one loaded in software) and I want to disable all sound if users uncheck the box.
But indeed, if you have more music files and samples, then you can better filter on which audio to pause.
Thanks for the information!
Logged
DarkTyranno
Guest
« Reply #5 on: 15 Feb '13 - 08:16 »
Reply with quoteQuote

I'm still trying to figure out how to use the mod tracks/samples from resource.
As the C++ sample shows, it looks like BASS has to search for the files in resources, while I rather tried:
musicload(properties.resource.myaudio, etc, etc);
Is there any documentation on the way this works, did anyone succeed, if possible in C#?
I can't just make up any code that works.. It should already exist but I can't find it.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #6 on: 15 Feb '13 - 18:06 »
Reply with quoteQuote

To play a resource, you first need to get the its memory location and size, which you can then pass to BASS_MusicLoad. In plain Win32, that involves the FindResource/LoadResource/LockResource/SizeofResource functions, as in the example snippet in the linked thread. You need to find out what the equivalent process in .Net is. I don't use .Net myself, so unfortunately I can't help much with that.
Logged
DarkTyranno
Guest
« Reply #7 on: 16 Feb '13 - 12:35 »
Reply with quoteQuote

I tried, but that snippet code doesn't work (obviously). I could Add 'Bass.' before the 'BASS_StreamCreateFile' etc, the functions I can use.
But before any of those other Resource method it fails. I tried different ones, like BASSAttribute, BASSFlag etc.. none works.
Searching in the available documentation I have, those methods weren't found... I can't try anything if I don't know how to use it or get it to work.
Everything I try to code is unknow for the program, so I can't continue. Someone must have made this or used this?
How does it work, please?? Sad
Logged
DarkTyranno
Guest
« Reply #8 on: 21 Feb '13 - 14:11 »
Reply with quoteQuote

It's been almost a week already. There must be somebody who knows this? Is it that rare to add music as resource to an applications so you don't have to send it with it all the time?
I need it badly for my project, as I make about 25 designs which all need other music, it becomes one big mess in my appdirectory and when I want to send an app to someone, I have to find the correct file to play, or it won't play.. And people don't have to put it in a specific directory anymore, that would be so great!
Anyone out there that can help me out?
Logged
saga
Posts: 1365


« Reply #9 on: 21 Feb '13 - 14:15 »
Reply with quoteQuote

Is it that rare to add music as resource to an applications so you don't have to send it with it all the time?
In the world of .NET, I don't think many people give a fuck about that. It's easy in unmanaged C++ as Ian pointed out.
However, someone out there in this world surely can help you... Programming is not about waiting for other people to give a ready-made solution for you, but also doing a bit of research on your own.
Also, there are other ways than resources to embed files in executables, such as converting the file to a byte array and then passing this byte array to BASS.
Logged
DarkTyranno
Guest
« Reply #10 on: 21 Feb '13 - 14:39 »
Reply with quoteQuote

Ah okay, I did research before asking, but I couldn't find it.
And as that code from C++ shows, it looked like I needed some BASS-related functions.
Sorry that I thought I was at the right place here, on the forum of the 'creators'?

I'll ask it on some other non-BASS-related forum then, maybe they know how to fix it.
I can't just come up with something if nothing works. Some things you must have done before
and my knowledge isn't as far as yours. But does that mean I have no rights to try to make an application with help?
Logged
saga
Posts: 1365


« Reply #11 on: 21 Feb '13 - 15:02 »
Reply with quoteQuote

Quote
And as that code from C++ shows, it looked like I needed some BASS-related functions.
The only BASS-related functions needed are those that load/play the actual music. To summarize it again, if you want to play a file from memory, you need its memory address and length. This means that you need to obtain the address and length of your resource (i.e. the equivlent to FindResource and LoadResource in Ian's example), and pass it on to BASS. That's all. Now maybe it's impossible to get the real address of you resources with managed code, but that's something I don't know since I don't code in .Net. It's something that should be pretty easy to find out, though, especially if you consider asking a more .Net-oriented community.
Logged
DarkTyranno
Guest
« Reply #12 on: 21 Feb '13 - 15:10 »
Reply with quoteQuote

Okay, thanks for the info. I shall move to another forum related to .NET then.
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines