How to play mp3 song file on SmartPnone

A

Anurag Saxena

I am using Process.Start(<MP3 file Name with path>) and able to run
the specific mp3 file but not be able to stop showing WMP. I want that
I will be able to play file but not want to display WMP interface.

I am using Win32Window.SetWindowPos() method for setting the windows
position but it vein.

Also the main part which I want to include in application is that I
will be able to find all mp3 files on smartphone and display in a list
so that I would be able to select and play it.Currently I am able to
find .wav files and display in a list and user is able to play
selected file(s).

I am making application for smartphone mobile and it windows mobile
and supported Windows CE.

Well..., Vishal, Be sure about the small gift(I am sure it would not
be small one) :)...It would be appreciable if you give some light on
use of windows media player 10 OCX.I don't its availability,use and
other details.

i am using C# and Visual Studio.NET IDE.

Thanks

Anurag
 
G

Grynn

<cite>
I am using Process.Start(<MP3 file Name with path>) and able to run the
specific mp3 file but not be able to stop showing WMP. I want that I
will be able to play file but not want to display WMP interface.
</cite>

Hmm. Since you are really Windows Media Player as a separate
application it is hard to prevent the Windows Media Player interface
being shown. I guess you could:

1. Start the Windows Media Player application as before
2. Wait for Input Idle (not sure about the managed equivalent)
3. Then send a VK_BACK to the Windows Media Player window (this will
involve doing a FindWindow() for a Window name/class which matches that
of Windows Media Player). This should cause Windows Media Player to
return focus to your application.
4. Then when you want to stop playback, Kill the Windows Media Player
process. You won't really know when the song has finished playing
because there is no feedback from Windows Media Player.

<cite>
I am using Win32Window.SetWindowPos() method for setting the windows
position but it vein.
</cite>

Expected.

<cite>
Also the main part which I want to include in application is that I
will be able to find all mp3 files on smartphone and display in a list
so that I would be able to select and play it. Currently I am able to
find .wav files and display in a list and user is able to play selected
file(s).
</cite>

Windows Media Player 10 Mobile has a "media library"; not sure
about how easy it is to access this. Which version of the smartphone
are you targeting?

I think that it will fairly hard to make a general solution using
Windows Media Player to play your MP3 files; especially since a lot of
devices will be running Windows Media Player 9 (Smartphone 2003 pre
AKU2 and older). You may be best of porting ffMpeg or a similar
library. Alternatively you could try porting mp3sharp.

Vishal.
 
A

Anurag Saxena

Hello Mr. Vishal,

Thanks a lot for your guidance .

I am very new to mobile application development and this is my second
project of handheld devices,although I am developing applications for
pocket pc and using XML there since aug,2004 but I am facing these
problems first time.so pls forgive me, if u r getting frustated.

However a good news is that I got success to display playlist and user
can select the song of his choice.

I am able to get the points which you described but don't know how it
will be implemented in C# for example 'Wait for Input Idle',how to use
VK_BACK and FindWindow().

I am not starting explictly WMP.I call the process.start(<mp3
filename>) and this line starts the media player.

There are functions of 'coredll.dll' named 'CreateProcess' and
'TerminateProcess',earlier I used 'CreateProcess' to start the
mediaplayer but at that time was not able to select the song.Now as I
am not using CreateProcess,how can I Terminate Process.Actually What I
understand is that anyhow, I should be able to kill instance of
mediaplayer or if not then atleast hide that so that when one song
finishes user able to select another,currently when I select a song
from list then...the Titlebar(on Top) and Menu(s)(on Bottom) changed
to WM Player's Title and Menu and Rest portion of window shows my
application interface but I am not able to select next song because of
MP players menu displayes not my applicaion menu.
because for song start,I select song from list and then choose
menu->play.

I am targeting windows mobile 2003 smartphone.

Now only functionality remaining is that user can select song
everytime means hide WMP interface.I am also thinking that if u guide
further then I am only 1 step back to completion.
Thanks,
Anurag
 
G

Guest

Hi - I am working on some kind of ringing bell and had the same problem. So
how did I solve the problem:
1. Use CreateProcess to start the WMP
2. As a parameter (commandline) you have to add the Mediafile(mp3...)
3. Wait a little while (Sleep(500))
4. Now switch the window SetForegroundWindow(HWND)
5. Use the process information from 2. to terminate the process

Beware - normally on smartphones you can run only one application instance.
So if there is already an WMP instance before you try to start one - the
process information given to you to eventually stop the MP won´t fit anymore.
In those cases you have to search the WMP-WindowHandle to Terminate that
process.
 
A

Anurag Saxena

I've done 4 steps as you suggested but now know how to terminate
process.
There is a method TerminateProcess of Coredll.dll but I don't know,
what parameters I should pass to terminate the process.
I did this as :

ProcessStartInfo psi = new
ProcessStartInfo("\\Windows\\wmplayer.exe");
psi.WindowStyle = ProcessWindowStyle.Minimized;
ProcessInfo pi = new ProcessInfo();
CreateProcess("wmplayer.exe", mp3song, IntPtr.Zero, IntPtr.Zero, 0, 0,
IntPtr.Zero, IntPtr.Zero, new Byte[128], pi);
System.Threading.Thread.Sleep(500);
Win32Window.SetForegroundWindow(handleofForm);
CurrrentThreadID= pi.ThreadID;
TerminateProcess(pi.ThreadID,1);
---------
There is a Class ProcessInfo as :
public class ProcessInfo
{
public int Process;
public int Thread;
public int ProcessID;
public int ThreadID;
}
---------------------------
The problem I am facing that I think line
System.Threading.Thread.Sleep(500);
not working and if somehow it works then how I decide the time to
sleep as the mp3 songs have different sizes.

Thanks,

Anurag
 
P

Paul G. Tobey [eMVP]

Well, you wouldn't terminate a thread ID. You'd have to pass the process
handle to TerminateProcess(). However, it's a really bad idea to count on
TerminateProcess(). If you look up TerminateProcess in the archives, you'll
find other things that you should try first to exit the target application.

Paul T.
 
A

Anurag Saxena

Now I am able to terminate WMP and
System.Threading.Thread.Sleep(500);
is also working but facing problem that how I decide the time to
sleep as the mp3 songs have different sizes.

It would be great If you guide about that is there any method/API
which tell me the total seconds of the song so that I can assign these
seconds to System.Threading.Thread.Sleep() method.

Anurag
 
A

Anurag Saxena

Well I'm sorry but still waiting for any response for the solution of
my smartphone mp3 song play project.It is the part that is still
remaining in project.
The problem still pending is that now I am able to terminate WMP and
also
System.Threading.Thread.Sleep(500);
is working fine but facing problem that how could I decide the time to
sleep as the mp3 songs have different sizes.
Is there any method/API that return the size or time so that so that I
can assign that seconds to System.Threading.Thread.Sleep() method.
Anurag
 
P

Paul G. Tobey [eMVP]

I don't think there's any way, other than by reading the file, seeing what
bit rate and what size you have, adding some slop time to account for the
time for the media player to load, load the file, and start playing, and
then sleep for that long. As far as I can tell, there's no way to
accurately figure this out. Maybe you can use the waveOutOpen() and
associated calls to actually play the song and know when it's done playing.
I've not done this, though, and can't confirm that it will work for .mp3
files.

Paul T.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top