How to Play Background Music using MonoTouch While App Running - c#

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.

Related

How to launch an external MP3 player without taking focus?

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.

Playing videos in background on Windows Phone 8.1

I'm creating a Windows Phone 8.1 app to play music and video from URIs. I first used a MediaElement control, to play media content.
However I can't play video or audio when my app is switched to background. I've implemented this (with BackgroundMediaPlayer) but this sample can only play audio, and I want my app to play video too.
I've searched a lot on the Internet, but I couldn't find the answer I'm looking for. So my question is : How can I play video in my app when it's switched to background?
If BackgroundMediaPlayer can't play video files in background I am almost sure there is no way to do it. That looks a little bit strange to play video in background.
But if your app is switched to the foreground, you can continue play video. Just save the last file in the mostRecentlyUsedList to have permissions to access this file the next time the app is opened.
Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(yourfile);
And later you can get it with:
String lastfilemruFirstToken = StorageApplicationPermissions.MostRecentlyUsedList.Entries.FirstOrDefault().Token;
StorageFile lastfile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(lastfilemruFirstToken);
The position you can get and set with the MediaElement.Position property

Background audio stops playing when minimize windows 10 universal

I created an radio app for windows 10 using mediaElement for audio output with AudioCategory = BackgroundCapableMedia but whenever I minimize the app on desktop or mobile the audio stops playing. So how do I keep the audio alive after I minimize? And all examples I find is for 8.1 silverlight applications
You need to implement a Background Task to keep audio alive when your application is minimized.
You can find a sample which targets Windows 10 on github. The project is splitted in 3 parts (a/ your main application b/ the background task and c/ code shared between the two first projects)
Background audio sample
In addition, you can find documentation associated to this sample on MSDN.
Background Audio
Please let me know if you need additional information.

Chartboost ad causes background music to pause in unity 3d android/ios app

I am working on my first mobile game which is mainly music based.
Whenever I show a chartboost interstital ad in my app(ios and android), the background music in my app pauses until the user closes the ad. Is there any way to change this behavior to keep background music playing while an add is shown(or possible never allow audio to be paused in unity or keep it playing during an application pause)?
I've tried searching all over, but couldn't find any info about this. Tried contacting chartboost support a few days ago, haven't herd a response yet either.
Any advice would be much appreciated ^_^

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.

Categories

Resources