How to launch an external MP3 player without taking focus? - c#

I am writing a desktop C# app to manage my MP3 library (it's essentially a bulk MP3 tag editor) and I want to be able to play songs while working on the library.
I do not want to embed a music player into my app and I am happy with whatever my system has configured to play music (in my case I have Groove Music set as a default player on Windows 10).
Launching a song is easy: simply call Process.Start(songPath);. The trouble is that Groove Music steals focus which is annoying because it breaks my work flow.
How can I launch an external music player so that it plays in the background and doesn't steal focus?
I have tried https://stackoverflow.com/a/19049930/497403 with the following command lines:
cmd.exe songPath
"c:\Program Files (x86)\Windows Media Player\wmplayer.exe" songPath
However, in both cases the music player window (Grove in the first case, Media Player in the second) still comes into foreground and steals focus.
I suppose I could, as a workaround, just embed Windows Media Player ActiveX in my app, but I'm still curious why I cannot get WMPlayer to start without grabbing focus, with SW_SHOWNOACTIVATE/SW_SHOWMINNOACTIVE and what-not.

Related

Is there a way to play audio with the screen off or in background on an app in Unity?

I have been looking for a way to have audio/music play on an app if the screen is either off or the user is not on the mobile tab of the app.
At first I tried to mess with some audio settings, then I tried looking into some of the project settings. I found some settings relating to running in background, but none of those solved the problem.
Even just a C# script that can go with Unity's audio system to play it with out being on would help if I found it.

Unity iOS Build - No audio when returning from Control Center with external audio playing

I have a Unity iOS app with Mute Other Audio Sources checked in Project Settings > Player. When I'm playing audio from another app on device and foreground my app, everything works as expected: the audio from the other app fades out and the audio from my app fades in.
However, when I have my app open and audio is playing, open up the iOS Control Center, start playing audio from another app (say, Apple Music, Apple Podcasts, or Spotify), and then close the control center, unexpected behavior occurs. The audio from the other app fades out as anticipated, but the audio from my app does not fade back in. All audio in my app remains muted/disabled/otherwise silenced as I continue playing, and only returns when I background and foreground my app again.
I have also received a user report that the app crashed when repeating these same steps (open Control Center, play music, close Control Center). I haven't been able to reproduce that bug, but I am concerned that this may be an issue for other users.
It's almost as if different audio behavior occurs in OnApplicationPause vs. OnApplicationFocus, but I haven't been able to get it to work even if I restart my AudioSource in either of these contexts.
I have reproduced this error in Unity 2019.4.17 and 2020.3.18. Not sure if it's a bug in Unity or if there's something I could be doing in my code to mitigate it. Let me know if I can provide additional information that would be helpful in addressing the issue. Thanks in advance for any advice you're able to give!
Update: Using Unity 2020.3.18 and iPhone 13, this only happens when the iOS device is on silent mode. The app normally plays audio even if the device is silenced, but fails to play audio if the device is silenced and I return to the app from the Control Center as described above. When I experience this issue, the audio plays after switching to ring mode. When the device is on ring mode from the start, everything works as expected.

MediaPlayer vs BackgroundAudioPlayer

I'm developing an Windows Phone application, that plays/streams music in background.
To accomplish that, I tried to use both Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer and Microsoft.Xna.Framework.Media.MediaPlayer classes.
In both cases everything worked just fine, so I was wondering, what are advantages/disadvantages of these methods, because now I can't decide which one is better.
The only thing that I don't like in BackgroundAudioPlayer, is that I need to create separate project for audio agent, and worry about transferring track info via IsolatedStorage. But since I've done that already. It's not a problem.
So are there any other differences between those two classes?
It depends on your program. If you want to play your background music only while using your program, you should use MediaPlayer. Otherwise you have to take care of the BackgroundAudioPlayer in any situation. Also this will annoy users, who also want to listen to their own music while using your application.
Otherwise, if your background music is the main purpose of the program, the user would like to start your music and switch to other programs. Then it keeps playing and you can control the music in the volume bar. That's why you have to create a background task for BackgroundAudioPlayer. The main application will stop in both ways when switching to other programs.
In short: game background music should never play after leaving the game (use MediaPlayer) - but I never want to watch my music player counting the time, while listening to my music library (use BackgroundAudioPlayer).
I believe MediaPlayer requires the application to be in the foreground. BackgroundAudioPlayer will let the user start a track, exit your application, and the music will continue to play and the agent can respond to the UVC.
Make sure you use a Mutex when you communicate between the foreground app and the background audio agent.

How to remove volume controls on lock screen in WP7?

When you stop your music which is playing in the music player, it doesn't really stop it. It just pauses it, as you are still able to see the music controls after you lock the screen. I want to remove the volume controls (rewind,play,forward) buttons which appear on the locked screen using the code behind. This has already been achieved by an existing app on the marketplace Stop the Music!. I have gone through this page, but still I am not able to understand how they are able to do so.
Is there anyway to achieve this??
Nice question, after some trial&error testing I've actually found out, how to remove the Music player from volume controls:
You need to add into your app empty file with .wma extension and set the build action as "Content", for instance "empty.wma" into the app root folder.
To stop the media playback and remove the media player just create dummy Song object and try to play it like this:
Song s = Song.FromUri("empty", new Uri("empty.wma", UriKind.Relative));
MediaPlayer.Play(s);
And that's all, because the file is invalid music file, nothing is playing and even the previous Music player has been removed.
Note I've tested this on Windows Phone 8 device with GDR3 update. Not sure, if it works as well on Windows Phone 7.5.
You don't need to do that now. Windows Phone 7.8 now have the music control as a popup when pressed volumn button on devices.

How to Play Background Music using MonoTouch While App Running

What would be the easiest way to have a music file included in the App as looped background music while the app is running and the music pauses if the app is suspended and starts up again when the app is brought back to foreground. Don't care about playing for the devices iTunes/Music catalog just one or more included music files within the App bundle.
I don't know if it's the easiest way, but there is some sample code in TweetStation to play audio in your app.

Categories

Resources