Problem with GHI Music Module

There a two possible issues:

First, you might not have waited long enough for the storage device to be recognized before mounting the file system.

The other possibility is you have not registered for an event from the music class. While you should not have
to register for an event, sometimes the drivers fail to check for registered users before firing an event, which
results in a null exception if there are none.

Add your mp3 as a resource and see if it works playing it from there.
That way we can easily tell if it is a problem with the sd which it sounds like…

@ Mike
I’ve added a

Thred.Sleep(5000)

to my code just after the program have mounted the SD card.
But I still get’s a System.NullReferenceException in GTM.GHIElectronics.Music.dll

@ Justin
I know how to add my music file to my Visual Studio project, but what should I write in my code to get the bytestream to load the music file directly from the Visual Studio project…?

@ jacob.lau1992 - just to see if its the music or sd that is the problem.

I know that Justin, but right now my code says it should read the music file, from my SD card. How can I get it to read it directly from the Visual Studio project…?

Sorry Jacob, was on my phone and misread your post.

Open up Resources.resx - Add Resource - Add existing File - Select your MP3.

music.Play(Resources.GetBytes(Resources.BinaryResources.MP3File));

Hi Justin.

Now i get a System.OutOfMemoryException occurred in mscorlib.dll in my Resources.Designers.cs class in this line:

        }
        internal static byte[] GetBytes(Resources.BinaryResources id)
        {
            return ((byte[])(Microsoft.SPOT.ResourceUtility.GetObject(ResourceManager, id)));
        }
        [System.SerializableAttribute()]
        internal enum BinaryResources : short
        {
            MP3 = -3767,
        }

How big is your MP3?

My MP3 file is only 88,0 KB

Can you post your current code…

Here is my current code…

using System;
using System.IO;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
using System.Threading;

namespace New_TeddyBear
{
    public partial class Program
    {
        private string _root;
        private static FileStream _fs;

        void ProgramStarted()
        {

            
            sdCard.MountSDCard();
           
            _root = sdCard.GetStorageDevice().RootDirectory;

            music.musicFinished += new Music.MusicFinishedPlayingEventHandler(music_musicFinished);
            music.SetVolume(255);
            music.Play(Resources.GetBytes(Resources.BinaryResources.MP3));
            //music.Play(LoadMusicFileBytes("1.mp3"));


        }


   

        //private byte[] LoadMusicFileBytes(string mp3)
        //{
        //    string fileName = Path.Combine(_root, mp3);
        //    try
        //    {
        //        _fs = new FileStream(fileName, FileMode.Open);
        //        byte[] b = new byte[_fs.Length];
        //        _fs.Read(b, 0, (int)_fs.Length);
        //        _fs.Dispose();
        //        return b;
        //    }
        //    catch (Exception ex)
        //    {


        //    }
        //    return null;
        //}
        void music_musicFinished(Music sender)
        {
            Debug.Print("Finished");
        }
    }
}

It looks like it doest like like your resource.

internal enum BinaryResources : short
        {
            MP3 = -3767,
        }

Pretty sure that should be a positive number.

If you want we could do a quick GotoMeeting and i could look over your shoulder…

Hi Justin.

That’s fine with me.

Do you host a meeting so I can Join you…?

Ping me an email and i’ll send you a meeting id

justin at ingenuitymicro dot com

Hi Justin.

I really really need your expert knowledge…

I really need the Cerb Mainboard to play something whatever music or a sound before tomorrow night Danish time.

I’am doing this for my girlfriend and she need it working with some music or a sound for a competition on wednesday.

I really hope you can help me…

Best Regards
Jacob Lau

Just sent you an email.