Jump to content

Audio Player on Smartphone using C#


Guest sebapi

Recommended Posts

Guest sebapi

I have some problem.

I can create application in Windows Application. I add a media player control from toolbox. I can create this application too without add media player control from toolbox, just add right library (WMPLib wmp.dll) and everything work.

I have question: in what way can I create some kind of mp3 player on Smartphone using C# ? On deviceApplication project I can't find media player control in toolBox, so I add WMPLib library into project, but when I start my application, there is no sound.

I've noticed that, when I go to bin/debug directory and execute the exe file the application works and there is sound.

Can anyone help me ?

Thanks.

Sebastian

Edited by sebapi
Link to comment
Share on other sites

What version of .NET CF are you using?

What is the device?

you cannot add a WMP SDK control on the mobile application as the SDK is for PC's

you can however play sound through WMP as I had demonstrated/explained in this thread:

[will post link to thread]

but generally you need to import the System.Diagnostics name space

Make a process and run Windows media player given it the path to the audio file you wish to play as an argument

so could be something like:

Process audioPlayer = new Process();

audioPlayer.StartInfo = new ProcessStartInfo("wmplayer", "pathToFile");

audioPlayer.Start();

this code is for .NET CF 2.0

Link to comment
Share on other sites

Guest sebapi

I've checked this solution:

Process audioPlayer = new Process();

audioPlayer.StartInfo = new ProcessStartInfo("wmplayer", "Baby.mp3");

audioPlayer.Start();

When I use mp3 file then it appears message like:

"Cannot play the file. The file is either corrupted or the Player does not support the format you are trying to play".

If I use wav file then it appears message like:

"Cannot play the file because the specified network protocol is not supported. If you entered a URL to play the file, try a different protocol (such as HTTP). If you clicked a link to play the file, the link might not be valid"

Hmm...

Do enyone have some idea ?

Link to comment
Share on other sites

Guest sebapi
Have you provided the full path to the file?

<{POST_SNAPBACK}>

Yes, I have tried with full path. Maybe I give a wrong path ? Where should be mp3 file physically ? Could you give me some example ? Maybe I have to set some settings in emulator ?

Link to comment
Share on other sites

\ << this is the root directory of the phone in general

so if your mp3 was stored in my documents on the phone memory, path would be:

\My Documents\baby.mp3

in .NET 2.0 I believe, perhaps not for CF I cannot remember, there is a special path class/special folder class which allows you to select a folder of a special system type (like Windows, or my documents) - see if you can find it (I think its in the environment class) and use that to guide the path to the mp3 file.

if you store the mp3 file on storage card, path:

\Storage Card\someFile.mp3

Link to comment
Share on other sites

  • 2 months later...
Guest StephenL
Process audioPlayer = new Process();

audioPlayer.StartInfo = new ProcessStartInfo("wmplayer", "Baby.mp3");

audioPlayer.Start();

Is there anyway to determine when the media clip has finished from within the C# code though? So that the player can be exited etc..

Cheers,

Steve

Link to comment
Share on other sites

  • 4 months later...
Guest aniljain
unfortunately not, that is only possible I believe in Windows and the WMP SDK, not on Windows Mobile

I tried to play mp3 file with the following code but it throws an error: "An object or name was not found" and when I try to play mp3 file I get the following error: "Cannot play the file. The file is either corrupted or the player does not support the format you are trying to play"

Process audioPlayer = new Process();

audioPlayer.StartInfo = new ProcessStartInfo("wmplayer", currentSoundTrack);

audioPlayer.Start();

Any idea??

Thanks

Anil

Link to comment
Share on other sites

  • 1 year later...
Guest keyur47831
make sure the path to the file is correct. It's been a while since I've done this but that could be one reason

By default the emulator does not support mp3 files. If u are checking the same on actual device, the code will work properly.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.