[Cf. Skills] playing audio files embedded in resources

Source: Internet
Author: User
[Cf. Skills]Play audio files of embedded Resources

Abstract: This article describes how to play audio files that sneak into resources on Windows Mobile.
Keywords
Playsound, Windows Mobile, embedded resources, P/invoke

What should I do if I want to play the audio file of embedded resources on Windows Mobile? Obviously, reflection is needed. I checked msdn. Fortunately, getmanifestresourcestream is available for mobile devices.

First, we need a class to use P/invoke to help us implement the playing sound function:

[Flags]
Enum Soundflags
{
Alias =   Zero X 00010000 ,
Filename =   Zero X 00020000 ,
Synchronous =   Zero X 00000000 ,
Asynchronous =   Zero X 00000001 ,
Memory =   Zero X 00000004 ,
Loop =   Zero X 00000008 ,
Nostop =   Zero X 00000010
}

Class Playnativeref
{
[Dllimport ( " Coredll. dll " , Entrypoint =   " Playsound " , Setlasterror =   True )]
Public   Extern   Static   Int Playsound ( Byte [] Szsound, intptr hmod, soundflags flags );
}

When calling, we must first extract the sound resource fromProgramLoad the set to memory:

Memorystream MS = (Memorystream) Assembly. getexecutingassembly (). getmanifestresourcestream ( " Playembeddedaudio.resources.yuyinlangdu.wav " );

TipsThe Resource Name here must be correct. If you are not sure, you can use the getmanifestresourcenames method to view the Resource Name.

Then, we can call the playsound method to play the video:

Playnativeref. playsound (
Ms. getbuffer (),
Intptr. Zero,
Soundflags. synchronous | Soundflags. Memory );


Note that the soundflag must add memory to indicate that the first parameter is to point to the audio file image in the memory. Load resources from memory during playback.

However, it should be noted that the embedded sound file should not be too many, otherwise it will make the Assembly very large.

CodeDownload from here

Enjoy it!

Yellow winter <fox23>

2008/5/18

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.