change the pattern of vibration in Firefox OS app - firefox-os

I want to provide a different pattern of vibration for the notification from my app . Is it possible to do that and , if possible , how ?

# Ishwar Patil You can change the number series so as to change the vibration pattern..Try this code:
var vibrate = document.querySelector("#vibrate");
if (vibrate) {
vibrate.onclick = function () {
navigator.vibrate(2000);
/*
Possible values:
On/off pattern:
navigator.vibrate([200, 100, 200, 100]);
Turn off vibration
navigator.vibrate(0);
*/
};

Related

Video Player always stay at the top in Cocos Creator?

I am developing a game where I want my textured image to remain on the top of video player but currently video player always stays on the top of all views?
I am using the CocosCreator framework and typescript.
VideoPlayer, EditBox and WebView Component are appended in cc.game.container so these component will add as last child and These will appear on the top.
By following these steps you can change the order or appearance.
If you wan to put something like a video player Behind the canvas and want to
put other component above it, So first you will have to make your canvas transparent. You can do this by setting the flag of engine file "/engine/cocos2d/core/platform/CCMacro.js"
Change the flag ENABLE_TRANSPARENT_CANVAS to true
You need the change the ZOrder of canvas and video component class in the start of the script responsible for video player.
start: function () {
cc.director.setClearColor(new cc.Color(0, 0, 0, 0))
let videoElement = document.getElementsByClassName('cocosVideo')[0];
videoElement.style.zIndex = 2;
let gameCanvas = document.getElementsByClassName('gameCanvas')[0];
gameCanvas.style.position = 'relative';
gCanvas.style.zIndex = 4;
},
3.Here is the complete script to play a video over canvas.
cc.Class({
extends: cc.Component,
properties: {
video:{
default: null,
type: cc.VideoPlayer
}
},
// use this for initialization
onLoad: function () {
this.videoPlayer = this.node.getComponent(cc.VideoPlayer);
this.videoPlayer.node.on('ready-to-play', this.callback, this);
},
start: function () {
cc.director.setClearColor(new cc.Color(0, 0, 0, 0))
let videoElement = document.getElementsByClassName('cocosVideo')[0];
videoElement.style.zIndex = 2;
let gameCanvas = document.getElementsByClassName('gameCanvas')[0];
gameCanvas.style.position = 'relative';
gCanvas.style.zIndex = 4;
},
callback () {
console.log("video ready to play")
this.videoPlayer.play();
},
// called every frame
update: function (dt) {
},
});

PhaserJS: After Rotation of camera dragging a Sprite gives strange coords

Basically the problem is that after you rotate the camera, the points that are given as arguments in the callback for dragging are not what I expected. I'm guessing I have to Rotate the given points also but I just couldn't.
Can Someone explain what is going on, is this some kind of bug or what should I do in order the sprite to follow the mouse cursor?
Easiest way to explain the problem is to reproduce it:
1) Go to Phaser Example Runner
2) Copy- Paste this code:
var config = {
type: Phaser.WEBGL,
parent: 'phaser-example',
scene: {
preload: preload,
create: create
}
};
var game = new Phaser.Game(config);
function preload ()
{
this.load.image('eye', 'assets/pics/lance-overdose-loader-eye.png');
}
function create ()
{
var image = this.add.sprite(200, 300, 'eye').setInteractive();
this.cameras.main.setRotation(Math.PI);
image.on('pointerover', function () {
this.setTint(0x00ff00);
});
image.on('pointerout', function () {
this.clearTint();
});
this.input.setDraggable(image);
this.input.on('dragstart', function (pointer, gameObject) {
gameObject.setTint(0xff0000);
});
this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
console.log(`x: ${dragX}, y: ${dragY}`);
gameObject.x = dragX;
gameObject.y = dragY;
});
this.input.on('dragend', function (pointer, gameObject) {
gameObject.clearTint();
});
}
3) Open the console, drag around the Eye and look at what coordinates are given.
4) If you remove line 24 (the rotation of the camera) Everything works as expected.
(The example is taken from Phaser 3 Official examples and a bit changed for the bug)
According to Phaser's API Documentation on the setRotation() method, the rotation given in radians applies to everything rendered by the camera. Unfortunately, your pointer isn't rendered by the camera so it doesn't get the same rotated coordinates. Not sure if this is a bug with the library or just a poorly documented exception, but I believe there is a workaround.
Create 2 variables to hold an initial position and a final position:
var image = this.add.sprite(200, 300, 'eye').setInteractive();
var initial = [];
var final = [];
Populate the initial position in your .on('dragstart') method:
this.input.on('dragstart', function (pointer, gameObject) {
initial = [
gameObject.x,
gameObject.y,
pointer.x,
pointer.y
];
gameObject.setTint(0xff0000);
});
Then, populate the final variable in your .on('drag') method:
this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
final = [
gameObject.x, // not necessary but keeping for variable shape consistency
gameObject.y, // not necessary but keeping for variable shape consistency
pointer.x,
pointer.y
];
gameObject.x = initial[0] + (initial[2] - final[2]);
gameObject.y = initial[1] + (initial[3] - final[3]);
});
All we're doing here is keeping track of the change in pointer position and mimicking that change in our gameObject.

UISlider with buffering progress - AVPlayer

I'm using AVPlayer to stream audio from a server and what I want to do now is to show a custom UISlider who shows the progress of the buffering.
Anyone come up with this? Please give me solution.
Now player load whole duration in once and show in UISlider.
you need to use preferredforwardbufferduration
This property defines the preferred forward buffer duration in seconds. If set to 0, the player will choose an appropriate level of buffering for most use cases. Setting this property to a low value will increase the chance that playback will stall and re-buffer, while setting it to a high value will increase demand on system resources.
also check here for detailed example of how to use : Is it possible to pause and resume buffering of AVPlayer?
inside your player you need to observe time range using below function
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?)
like this:
let timeRanges = change![NSKeyValueChangeKey.newKey] as? NSArray
if timeRanges != nil && timeRanges!.count != 0 {
DispatchQueue.main.async {
let cmTimeRange = (timeRanges![0] as AnyObject).timeRangeValue as CMTimeRange
self.playerView.timeSlider.bufferValue = Float(CMTimeGetSeconds(cmTimeRange.start) + CMTimeGetSeconds(cmTimeRange.duration))
}
}
I have a custom slider with a variable I defined as bufferValue you can override func draw(_ rect: CGRect)inside your slider and apply changes while buffer is progressing.
I get draw to call anytime bufferValue changes by calling self.setNeedsDisplay()inside didSet
#IBInspectable var bufferValue : Float = 0 {
didSet {
if(bufferValue < 0 ) {
bufferValue = 0
} else if (bufferValue > maximumValue) {
bufferValue = maximumValue
}
self.setNeedsDisplay()
}
}

Phaser: show text when sprites overlap

I am trying to work out a way to add a text to the top left corner of the viewport when two of my sprites overlap. One of them is an item and the other is my character. I can already detect for overlap and even "pick" the item (kill the sprite) when I click a key. However I would like that a text saying something like "Click "E" to pick the sword!" appeared while the collision function is active and when I kill the sprite by picking it up the text would vanish.
I tried including the text in the collision function itself but I suppose this way I am rendering the text multiple times (the fps drops a lot) and I just want to create it once and remove it according to my purposes. My code:
function collisionHandler(dude,the_sword) {
pickObject.onDown.add(function () {
the_sword.kill();
}, this);
}
game.physics.isoArcade.overlap(dude, the_sword, collisionHandler, null, this);
// message saying to pick // Where to put this?
var style = { font: "30px Arial", fill: "#ff0044"};
var pick_message = this.game.add.text(0,20,"Click 'E' to pick up the sword!",style);
pick_message.fixedToCamera = true;
Any idea on how to do this?
In your 'create' function:
var style = { font: "30px Arial", fill: "#ff0044"};
var pick_message = this.game.add.text(0,20,"Click 'E' to pick up the sword!",style);
pick_message.fixedToCamera = true;
pick_message.visible = false;
Then:
function collisionHandler(dude,the_sword) {
pick_message.visible = true;
pickObject.onDown.add(function () {
the_sword.kill();
pick_message.visible = false;
}, this);
}
game.physics.isoArcade.overlap(dude, the_sword, collisionHandler, null, this);
Something like that should work. If you want to perform other action, like opening the door, you can use:
pick_message.setText("Click 'Q' to open the door!");
You don't have to create new text evertime, you can use one for different purposes.

How can I integrate a navigator app on a device

What is the best approach to make use of navigation features like route planning when I have an address in my Movelet and want to trigger a navigation via an external app on iOS, Android and Windwos Phone?
To jump into another app you need the Movilizer AppJump feature, with this you can open a connection (Module SPI) and trigger the execution in use of the exec command. What you or the user still has to do is to start the navigation manually by pressing the Start button in the maps app.
For the Android Client you need to use the protocol named geo. Geo gives you two opportunities, you can either enter the specific coordinates or enter an address.
The use of specific coords will look like this:
'geo:49.483611111111,8.463055555555697?z=18'
In case you don't know the coords you can also use:
'geo:0,0?q=Wilhelm-Varnholt-Allee 1, 68165 Mannheim?z=18'
In your code it will look like that:
if(platform == 11)
{
intentURL = conCat('geo:0,0?q=', destPoint,'?z=18');
conStr = conCat('exec:', intentURL);
}
For the iOS Client the URL scheme looks quite similar, but instead of using geo you need to use to point on the app which you want to open.
'exec:maps://?q=Wilhelm-Varnholt-Allee 1, 68165 Mannheim?z=18'
The use of maps:// will open the Apple Maps app if you want to have Google Maps you must use comgooglemaps://
I've prepared a small example this may helps you to solve the problem you have:
<question key="#1" type="6" title="Address">
<answer key="#1_0" nextQuestionKey="END" dummyAnswer="true"/>
<onEnterAssignment>
addresses =
{
'Diakoniekrankenhaus Mannheim' : 'Speyerer Str. 91, 68163 Mannheim';
'Moll-Gymnasium' : 'Feldbergstraße 16, 68163 Mannheim';
'Planetarium Mannheim' : 'Wilhelm-Varnholt-Allee 1, 68165 Mannheim';
'Karl Benz Stadion' : 'Theodor-Heuss-Anlage 20, 68165 Mannheim';
'Luisenpark' : 'Theodor-Heuss-Anlage 2, 68165 Mannheim';
'Mannheim City Airport':'Seckenheimer Landstr.172, 68163 Mannheim';
};
for(dest:addresses)
{
addAnswer($answer:'#1_0', dest, dest);
}
platform = getClientType();
</onEnterAssignment>
<onLeaveOkPersistAssignment>
destPoint = addresses[getQuestionValue()];
if(platform == 11)
{
intentURL = conCat('geo:0,0?q=', destPoint,'?z=18');
conStr = conCat('exec:', intentURL);
}
else
{
conStr = conCat('exec:maps://?q=', destPoint, '?z=18');
}
conID = connect(conStr, null);
if(isConnectionOpen(conID))
{
close(conID);
}
</onLeaveOkPersistAssignment>
I've also found another way on Android:
addressTxt = "Wenceslas Square, Prague, CZ";
connStr = concat("exec://", "%com.google.android.apps.maps%", "http://maps.google.com/maps?daddr=", addressTxt);
connection = connect(connStr, "name");
try
{
close(connection);
}
catch (exception)
{
}
Result on YouTube
For the navigation on Android, the following worked for me.
intentURL = '%com.google.android.apps.maps%google.navigation:q=Address';
conID = connect(concat('exec:', intentURL), "name");
if (conID ?ge 0)
{
close(conID);
}
Address could be: RMZ Eco World Rd, Adarsh Palm Retreat Villas, Bellandur, Bengaluru, Karnataka 560103, India

Resources