hello,
Actually, i want to play sound file from resource. I am using WindowMediaPlayer Control for window application. But there is only option is "URL" (Property of control) to play sound file. I don't want to use URL property. Because my sound file is present in the Resource.

Any body help me... How is it possible?
If my question is not clear then tell me i explain ti again. but plz help me.


I also want to use flash file(.swf) for WebBrowser control but not using URL Property and also without using sartup path. Means i want to use Resource path

IN C#

Dani AI

Generated

you are right that the WMP control wants a URL. is also right that your asset lives in Properties.Resources, but the WMP ActiveX cannot read from a .NET Stream directly. The practical bridge is: write the resource to a temporary file, then point WMP at that file path. This keeps the media embedded in your app and avoids shipping loose files next to the EXE.

Example (WinForms, C#):

using System;
using System.IO;
using WMPLib;            // add COM ref: Windows Media Player
using AxWMPLib;         // Windows Media Player control

// Write resource to a temp file and play it
void PlayFromResource(AxWindowsMediaPlayer wmp)
{
    string temp = Path.Combine(Path.GetTempPath(),
        "mysound_" + Guid.NewGuid().ToString("N") + ".mp3");

    using (Stream src = Properties.Resources.MySoundMp3) // Stream or byte[] via a MemoryStream
    using (FileStream dst = File.Create(temp))
        src.CopyTo(dst);

    wmp.settings.autoStart = true;
    wmp.URL = temp;

    wmp.PlayStateChange += (s, e) =>
    {
        var st = (WMPPlayState)e.newState;
        if (st == WMPPlayState.wmppsStopped || st == WMPPlayState.wmppsMediaEnded)
        {
            try { File.Delete(temp); } catch { /* may still be locked; delete on exit instead */ }
        }
    };
}

For a .swf in WebBrowser, the same idea applies: write the resource to a temp .swf and navigate to that file path.

string swf = Path.Combine(Path.GetTempPath(), "movie_" + Guid.NewGuid().ToString("N") + ".swf");
File.WriteAllBytes(swf, Properties.Resources.MyMovieSwf);
webBrowser1.Navigate(swf);

Notes:

  • Ensure the resource Build Action is Embedded Resource (or add via Project Resources so you get a strongly-typed property).
  • Clean up temp files on FormClosed as a fallback.
  • Modern Windows no longer supports Adobe Flash, so the .swf approach only works on older systems that still have the Flash ActiveX control installed.

Recommended Answers

All 5 Replies

using System.Media;

SoundPlayer m_MySound = new SoundPlayer(Properties.Resources.YourSoundFile);


//invoke as this

m_MySound.Play();

as far as the swf control use the same method Properties.Resources.whatever

Sorry! friend.
But i am not using SoundPlayer.
I am using WindowMediaPlayer Control which have only URL property to play sound file.
Also i am not using swf control, i am using WebBrowser Control to play .swf (flash file). It has also URL property or we can use startup path.

plzzzzz help me ....Read my question.

Sorry! friend.
But i am not using SoundPlayer.
I am using WindowMediaPlayer Control which have only URL property to play sound file.
Also i am not using swf control, i am using WebBrowser Control to play .swf (flash file). It has also URL property or we can use startup path.

plzzzzz help me ....Read my question.

You missed the point of my response its not what you are using rather that getting to any resource that is in your project is located as Properties.Resources.XXXXXX

You missed the point of my response its not what you are using rather that getting to any resource that is in your project is located as Properties.Resources.XXXXXX

my brother,
we can not write like this xxxxxx.URL=Properties.Resources.XXXXX Please bro try to understand my problem.
but you are trying to solve my problem, so thank's for your help and help again plzzzzz

my brother,
we can not write like this xxxxxx.URL=Properties.Resources.XXXXX Please bro try to understand my problem.
but you are trying to solve my problem, so thank's for your help and help again plzzzzz

OK get rid of the WMPlib. Its not needed, instead once you have the file added as a resource( "add existing Item" in your solution explorer) then add this code to a button event or your form load event.

Dim process As System.Diagnostics.Process
process = New Process(Me.GetType().Assembly.GetManifestResourceStream _
("ApplicationNamespace.SoundFile.mp3")

WMPlib is used to create a Windows media player that will play files in the same directory as the app or as a movie player for media on the web (hence the .URL) It requires that the media be fed via URL link and only in a link. The code that I gave you earlier is also a good replacement for it as it does Not need the URL and will also implement the application resource information. Here is the Microshaft link for WMPlib (wmp.dll) This will explain it better and the limits within the library. Here is an example of its use.

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.