Audio Streaming in windows phone app (no Silverlight) - c#

I am trying to play an audio stream from stream server in my windows phone app. I read on Microsoft Documentation that I have to reference an Audio Stream Agent.
I have these projects in my solution :
I've tried to reference a new project as Audio Streaming Agent in my Windows Phone 8.1 application
but I keeping receiving the error :
I read that I have to change the target framework, but there is no option for target framework in the AudioStreamAgent1 properties.
Also, Can I do this using an application that is not the Silverlight kind? Is there a way to do without using the Silverlight one?

The problem is that the AudioSteamAgent is targeted at WP Silverlight, and your actual app is WP8.1 (WinRT).
To create background audio in WP8.1, you will want to use the Background Media Player.
You can find a great guide for how to get started here.
But basically (without all the boilerplate code to wire everything up), it comes down to telling the BMP what to play (code is from the link above):
BackgroundMediaPlayer.Current.SetUriSource(new Uri("ms-appx:///Assets/Media/Ring02.wma"));
BackgroundMediaPlayer.Current.Play();
And telling the OS player controls what to show, and what to do when the user interacts with them:
systemmediatransportcontrol = SystemMediaTransportControls.GetForCurrentView();
systemmediatransportcontrol.ButtonPressed += systemmediatransportcontrol_ButtonPressed;
systemmediatransportcontrol.PropertyChanged += systemmediatransportcontrol_PropertyChanged;
systemmediatransportcontrol.IsEnabled = true;
systemmediatransportcontrol.IsPauseEnabled = true;
systemmediatransportcontrol.IsPlayEnabled = true;
systemmediatransportcontrol.IsNextEnabled = true;
systemmediatransportcontrol.IsPreviousEnabled = true;
This is all assuming that you want the user to be able to leave the app and have media continue to play. If you just want to stream audio/video while the user is in the app you can use the MediaElement control.

Related

Can I create an alarm app for Window Universal App?

I would like to create an alarm app.
I found the way of operating a timer in the background. But APIs which control the power of the display were not found(I want to turn on the display's power when its power is off).
Doesn't Windows 10 (Windows Universal App) have enough APIs to create that app?
Windows-universal-samples has recently been updated with a few new RTM samples including this one - Notifications.
As Alarm is also one type of notification, it's now built within a new toast notification framework in the Universal Windows Platform.
After you downloaded the source code from the Notification's link above, run it with Visual Studio 2015 RTM and then once the app is loaded, go to
toasts > scenarios > scenario: alarm
and you will see a fully functional alarm app (along with Reminder and a lot other samples).
Let's talk about code.
Basically, unlike in Windows Phone Silverlight, you can now customise the alarm popup a bit by specifying the xml payload like this (make sure the scenario is set to alarm)
<toast launch='args' scenario='alarm'>
<visual>
<binding template='ToastGeneric'>
<text>Alarm</text>
<text>Get up now!!</text>
</binding>
</visual>
<actions>
<action arguments = 'snooze'
content = 'snooze' />
<action arguments = 'dismiss'
content = 'dismiss' />
</actions>
</toast>
And then create an XmlDocument which loads the above xml string
var xmlString = #"//copy above xml here//";
var doc = new Windows.Data.Xml.Dom.XmlDocument();
doc.LoadXml(xmlString);
Then create a ToastNotification and trigger it with ToastNotificationManager-
var toast = new ToastNotification(doc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
That's it! You will see an alarm popup like below.
Update
Microsoft recently responded to one of my API requests and I am posting the content here so everyone knows what APIs have been added and what are still outstanding.
What has been done
There is now a way to create an alarm/reminder in universal windows
apps;
The alarm/reminder supports custom snooze time (you can choose to
let system handle snooze, or wake up your background task to do it
manually);
The alarm/reminder supports vibrate only (just like toast) that can
be overwritten by user to turn off vibration;
The alarm/reminder supports a good level of customizability (custom
optional inline image, custom additional actions, etc).
Some references
Adaptive and interactive toast notifications for Windows 10
Toast Notification and Action Center Overview for Windows 10
Quickstart: Sending a local toast notification and handling
activations from it (Windows 10)
What we (MSFT) know that’s missing and hope to support in the near future
Native platform support in alarm/reminder to automatically handle time conversion when time-zone changes (Workaround – this can be done by the app manually by using the TimeZoneChange system trigger);
Native platform support in alarm/reminder for recurrence events (Workaround – this can currently only be done by the app manually periodically waking up and reschedule a bunch of alarms/reminders ahead of time);
Native platform support to select a song from Music library as ring tone for alarm/reminder (Workaround – this can be done by reading and copying files from your music library, and then use the saved/modified version of the file in your app package or app data as the ring tone (toast notification supports custom sound by pointing to files in appx or appdata in the xml payload)).
AlarmApplicationManager can be used to create alarm apps. It gives capabilities to schedule toast notifications.
var scheduledToast = new ScheduledToastNotification(content, DateTime.Now.AddMinutes(5));
toastNotifier.AddToSchedule(scheduledToast);
An audio source can also be set while creating the toast template, but only from a set of predefined sounds supplied by windows.
Refer AlarmApplicationManager and Building alarm app for more details.
There are a number of Win 10 Universal Samples on GitHub which may be useful. I didn't see anything directly related to Alarms, though.
unfortunately Windows Universal Applications have no direct access to the Display Settings. But you can use the AlarmApplicationManager Class to create an Alarm. This will, in some cases (for sure on WindowsPhone) turn on the display automatically to show off the Alarm (with Title and Description).

Exception only in one PC, in others work fine

I have an exception only in one PC, in others all work fine, anyone know wher it is comming from?
dditional information: Requested Windows Runtime type
'Windows.Media.Capture.MediaCapture' is not registered.
This exception is showing only in modern style apps (windows strore app) in windows 8.1. In WPF or Windows Form apps camera works fine. Code is fine, because in other pc work great:) i install system one more time, but the exception still showing up.
Looking at Microsoft's Windows Universal Samples (https://github.com/Microsoft/Windows-universal-samples/blob/e13cf5dca497ad661706d150a154830666913be4/Samples/SpeechRecognitionAndSynthesis/cs/AudioCapturePermissions.cs#L35) shows following piece of code
try
{
// Request access to the microphone only, to limit the number of capabilities we need
// to request in the package manifest.
MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
settings.StreamingCaptureMode = StreamingCaptureMode.Audio;
settings.MediaCategory = MediaCategory.Speech;
MediaCapture capture = new MediaCapture();
await capture.InitializeAsync(settings);
}
catch (TypeLoadException)
{
// On SKUs without media player (eg, the N SKUs), we may not have access to the Windows.Media.Capture
// namespace unless the media player pack is installed. Handle this gracefully.
var messageDialog = new Windows.UI.Popups.MessageDialog("Media player components are unavailable.");
await messageDialog.ShowAsync();
return false;
}
So you have to install "Media player components".
I just had this issue with Windows 10. I had installed the N edition, but it looks like since it is missing Media Player, the classes related to MediaCapture are also missing.
As Hans Passant mentioned, the MediaCapture class was not registered in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsRuntime\ActivatableClassId.
I reinstalled Window 10 (not the N edition) and now the class is registered.

Using CameraCaptureTask to launch the default camera app

Windows Phone 8 gives the ability to change the default camera app with another one downloaded from the store, making this new app the one that's launched when you hit the camera hardware button.
So I was wondering if is there any chance to launch this app using the CameraCaptureTask.
What I'd like to do is something simple like
var camera = new CameraCaptureTask();
camera.Show();
camera.Completed += new EventHandler<PhotoResult>(camera_Completed);
but I want this to work with the default app that the user chose on its device, and not with the basic Microsoft's one.
I've not found anything online, so I'm asking to you guys if I can make what I want.
Sorry, not possible with the current API.

How to stream from soundcloud without using API In windowsPhone 8 Application?

I Develop windows phone application and i want to stream audio from sound cloud without using sound cloud API ( i write this Code
"webBrowser1.NavigateToString("<!doctype html>" + "<html><head><title></title></head><body>" + "<iframe height=\"1000\" src=\"https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/125791854\" width=\"1200\"></iframe>" + "</body></html>");"
and C# and using web Browser Control In Xaml Page in but when i Run it it load sound cloud site but the audio didn't run.
Try Background Audio Player, here is a sample , basically what you will end up doing is
new AudioTrack(new Uri("[your soundcloud uri]", UriKind.Absolute), "[Track Name]", "[Artist]", "[Album]", null)
Things to note :
Url should be something like : http://api.soundcloud.com/tracks/[trackNo]/stream?client_id=[id]
You need to wait for the PlayerState to change to track ready and then call .Play(), This is due to the asynchronous nature of the background audio player. It actually resides in a different process than the rest of the code.

Windows Phone - Audio Endpoint Device

I can't seem to find this anywhere.
I want to build an Audio Endpoint device that plugs into the Windows Phone Headphone Jack.
I know I need to start with what the phone is capable of receiving and detecting.
Ultimately I would like to use already in existence libraries however I have no heartache about writing my own.
My problem is I can't find any examples of how people access the Audio input on the phone outside of the built in microphone.
Is there a library for this?
You can detect when a headset is plugged in using the VOIP capabilities in Windows Phone 8.
First in the WMAppManifest.xml file, you need to enable ID_CAP_VOIP and ID_CAP_AUDIOROUTING
Then in the App, you need to capture the event
AudioRoutingManager.GetDefault().AudioEndpointChanged += AudioEndpointChanged;
public void AudioEndpointChanged(AudioRoutingManager sender, object args)
{
var AudioEndPoint = sender.GetAudioEndpoint();
switch (AudioEndPoint)
{
case AudioRoutingEndpoint.WiredHeadset:
MessageBox.Show("Headset connected");
break;
}
}
This will enumerate from this list (no custom endpoints allowed)
http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.media.devices.audioroutingendpoint(v=vs.105).aspx
Sorry, but I can only answer the first part of your question about detecting the device, I'm not familiar with how the hardware device interfaces with the headphone jack to answer the rest.

Categories

Resources