how to play audio through earpiece only in windows phone 8 application - windows-phone-8

I have tried with AudioRoutingManager class...but i got unauthorizedaccess exception.
here is my code
AudioRoutingManager audioRouting = AudioRoutingManager.GetDefault();
public AudioRoutingEndpoint ChangeAudioRoute()
{
var currentEndPoint= audioRouting.GetAudioEndpoint();
switch (currentEndPoint)
{
case AudioRoutingEndpoint.Earpiece:
case AudioRoutingEndpoint.Default:
return AudioRoutingEndpoint.Speakerphone;
case AudioRoutingEndpoint.Speakerphone:
return AudioRoutingEndpoint.Earpiece;
default:
throw new OperationCanceledException();
}
}
public void SetAudioRoute()
{
audioRouting.SetAudioEndpoint(this.ChangeAudioRoute());
}

The APIs in the Windows.Phone.Media.Devices namespace require the ID_CAP_AUDIOROUTING and the ID_CAP_VOIP capability. (Add this to your manifest)
Also, it's only possible to change the audio routing while in a active VOIP call.
Additionally, you need to do the audio routing in your background VOIP process, and not in the foreground process.

Old question but now I know the answer.
Two things which you need to do:
Tag the audio in question as "communications"
How to do this depends on what API you're using. It could be as simple as . Or you might have to call IAudioClient2::SetClientProperties with an AudioClientProperties structure whose AudioClientProperties.eCategory = AudioCategory_Communications.
Tag your app as either a "voice over IP" app or a "voicemail" app
You should add file called WindowsPhoneReservedAppInfo.xml to your project with the following contents:
<?xml version="1.0" encoding="utf-8"?>
<WindowsPhoneReservedAppInfo xmlns="http://schemas.microsoft.com/phone/2013/windowsphonereservedappinfo">
<SoftwareCapabilities>
<SoftwareCapability Id="ID_CAP_VOIP" />
</SoftwareCapabilities>
</WindowsPhoneReservedAppInfo>
Look for more detailed explanation here:
Playing audio to the earpiece from a Windows Phone 8.1 universal app

Related

How to upload attachments in browser tests using Appium?

I am trying to automate a test case in Chrome where I would like to upload an attachment to an email. I use desiredCaps['browserName'] = 'Chrome'. While clicking attachments in email, it opens the Documents in the phone, but I am unable to detect the elements in the Documents screen.
Try this.If you are using ruby
This basically goes into the directory called screenshots and finds the second picture or the document that is visible inside the directory
find_element(id: "screenshots").find_element(class: "android.widget.ImageView[2]").click
end
This captures the first document/picture visible in the gallery
find_element(id: "").find_element(class: "android.widget.ImageView").click
You can modify it as per your requirement
You shoud change context to from Chromium to 'NATIVE_APP' appium doc about it (http://appium.io/docs/en/writing-running-appium/web/hybrid/) and use Touch Actions for choose you file
In Java, you can use the below code to switch context.
Set<String> contextNames = driver.getContextHandles();
for (final String contextName : contextNames) {
if (contextName.contains("NATIVE")) {
driver.context(contextName);
System.out.println("Switched to Native Context");
}
}
in Python you can try something like this
contextNames = driver.contexts
for aContext in contextNames
if "NATIVE" in aContext:
driver.switch_to.context(aContext)

Vimeo Embed Language/Subtitles

I'm using Vimeo to host video files for a project however the videos can be in up to 8 languages. We are using subtitles PER VIDEO to split the languages up (1 video, 8 subtitle files).
The problem is I'm not able to find in the API docs or anywhere else if there's is a possibility of setting the language of the subtitles using the API or perhaps the iframe embed attributes.
Any help on this matter would be much appreciated. Thanks!
To all who are curious, I ended up building my own subtitle engine. The client had the subtitle files already created so using those and some clever JS parsing found online I was able to recreate subtitle functionality on my end.
Let me know if you need help with that :)
Duplicate of Vimeo force CC language
You can use the enableTextTrack function on a player initialized by the JS API provided by Vimeo:
// Select with the DOM API
var iframe = document.querySelector('iframe');
var iframePlayer = new Vimeo.Player(iframe);
player.enableTextTrack('en').then(function(track) {
// track.language = the iso code for the language
// track.kind = 'captions' or 'subtitles'
// track.label = the human-readable label
}).catch(function(error) {
switch (error.name) {
case 'InvalidTrackLanguageError':
// no track was available with the specified language
break;
case 'InvalidTrackError':
// no track was available with the specified language and kind
break;
default:
// some other error occurred
break;
}
});
More information on the github of Vimeo player JS API: https://github.com/vimeo/player.js#enabletexttracklanguage-string-kind-string-promiseobject-invalidtracklanguageerrorinvalidtrackerrorerror

Windows RT/ Universal app, Webview offline html file

( creating a universal app, currently working one windows phone 8.1) I am trying to get the webview to work with an offline html file but i cant really figure it out. I can get it to work with a weblink but not with an html file which is located on the shared folder.
I'm using switch statement to switch through different options. Here is a sample one with the code i use
case "Test":
ActualLoad = "Test.html";
break;
Here is the one that has a link:
case "OnlineTest":
ActualLoad = "https:www.google.com";
break;
The second one works but not the first one.
Check out the Remarks in this MSDN page.
Basically, you have to use something like this: <WebView Source="ms-appx-web:///Test.html"/>
This will work only if your Test.html file exists in your app package.

Universal App (HTML5) deployment to Windows Phone fails when using Background Audio

I am developing a Universal App that uses the HTML5 / JavaScript framework. In this app I have a page with an HTML audio tag (with the attribute msAudioCategory set to "BackgroundCapableMedia"), that is further wired up with Windows.Media.SystemMediaTransportControls.getForCurrentView() in order to get the audio playing in the background. I also have, on both the windows and phone projects, set the Declarations > Background Tasks > Audio, with the default.html page set as the entry page.
Deploying to Windows (either local machine or emulator) works as expected. All to the good. However deploying to either the phone emulator or a physical phone device throws this rather unhelpful error:
Unexpected Error: Package could not be registered. (Exception from HRESULT: 0x80073CF6)
Cant see any obvious reason for this. Searching the net suggests that this might be a bug, but I also suspect that playing background audio on the phone might require a different methodology.
Notably, starting a new blank universal app, adding the declaration as above (with no audio tag or supporting code), deploys on windows but fails with the same error on the phone. Any ideas?
Have discovered the issue that the rather uninformative error was trying to tell me: my entry point was invalid. As mentioned I had it set it to the default.html page, but for the windows phone at least it needs to be set to a valid background task file. In C# this is something that inherits from the Windows.ApplicationModel.Background.IBackgroundTask interface. In JavaScript, this is a JS file that looks a little like this:
(function () {
var backgroundTaskInstance = Windows.UI.WebUI.WebUIBackgroundTaskInstance.current;
function doWork() {
var settings = Windows.Storage.ApplicationData.current.localSettings;
var key = backgroundTaskInstance.task.taskId.toString();
settings.values[key] = "Succeeded";
close();
}
if (!canceled) {
doWork();
} else {
key = backgroundTaskInstance.task.taskId.toString();
settings.values[key] = "Canceled";
close();
}
})();
Taken from the sample here: http://msdn.microsoft.com/en-us/library/windows/apps/hh977045.aspx
Cheers :D
WindowsPhone 8.1 do not support background audio by JavaScript. You should use c# for this task. That is all.
"Important:
You can use JavaScript to write background audio applications. However, Windows Phone 8.1 does not allow JavaScript to run in a background process. Which means, your foreground app and UI can be written in JavaScript, but your background task must be written in C# or C++. The Background audio for Windows Phone 8.1 sample provides an example of a JavaScript app that supports background audio by using a C# background agent."
https://msdn.microsoft.com/en-us/library/windows/apps/dn720802.aspx

Possible channels of communication between Javascript on HTML page and a windows EXE?

Here's the thing.
A two-way communication (RPC-style) is needed between JavaScript on HTML pages provided by a web server online (with session-management and whatnot) and a windows EXE application running on the PC of the website visitor.
Both are parts of the same 'package' and should be able to communicate.
There is the use of a custom protocol for sure, but some browsers like Chrome & Safari sometimes have issues with custom protocol handling, so it is not reliable enough ...
Another possibility is to build a minimal web-server inside the EXE, so the communication would work with all browsers.
It is possible to develop an extension / plugin for each browsers separately, but it's a daunting task..
The usage of flash / java seems not possible for this task because of sandboxing, but I'm not sure about this ??
Do you have any other ideas ?
You can use an embedded ActiveX (COM) object and communicate between both platforms. I've done it (and would not have believed it possible had I not). It's nasty but it works. In the project I used it on I had no choice (which is about the only reason to ever do this). I built the COM object in C#.net and exposed an interface to COM for use on the page. It goes something like this:
function doSomethingInteresting() {
// in your js:
var obj = document.getElementById('yourObjectId');
obj.MethodNameDefinedOnYourCOMObject("someParameterValue");
}
// and your HTML looks like this; note that you can even catch events thrown from the COM object in Js...
<body>
<form>
<object id="yourObjectId" height="0" width="0" classid="clsid:99999999-9999-9999-9999-999999999999" onerror="oError()" VIEWASTEXT></object>
<script for="yourObjectId" event="ThisIsTheJavaScriptEventHandlerMethod(parameterName)" language="javascript">
// event handling here for the COM object
function yourObjectId::ThisIsTheJavaScriptEventHandlerMethod(parameterName) {
// you can process the parameterName passed from the object here
}
</script>
</form>
</body>
Happy coding!