Way to "preload" Canvas animation before showing the page? - android

I have started experimenting with the WebView in order to display locally stored HTML files that play some fairly basic Canvas animations (using the CreateJS library).
They seem to play really well but some times, the page is loading and playing the animation before images are fully loaded (e.g. one animation has a fairly large background image ~1mb)
Is there a way to either "speed" things up, "preload/prefetch" the images (and other assets if need be) or simply wait till the app has loaded the images into its memory (if it does that) before displaying and starting the animation?
To add to that last question, is there a way to "pause" the animation and only play it once the images have fully loaded?
Thanks

Try with onload event which runs after all images or external resources are loaded:
$(window).load(function(){
//code
});
or you can try with load event for individual images and run your code when they have loaded:
$('img.imgClass').load(function(){
// The image loaded,,, code
});

The CreateJS suite includes PreloadJS, which is a pretty decent way of preloading content that is used by EaselJS, or any other content for that matter.
http://preloadjs.com
You can pre-fetch images, javascript, audio, JSON/text/XML, SVG, CSS, etc.
var queue = new createjs.PreloadJS();
queue.addEventListener("complete", handleComplete);
queue.loadManifest([
{id: "image", src:"image.png"},
{id: "image2", src: "image2.jpg"},
{id:"script", src:"script.js"}
]);
function handleComplete(event) {
var image = queue.getResult("image"); // Returns an image tag
}
There are some workarounds to preload audio (with multiple formats), or use tag loading to get around cross-domain issues. Check out the docs for more:
http://www.createjs.com/Docs/PreloadJS/modules/PreloadJS.html

You can do it like this:
create a function that should do this:
loadData();
loadData = function()
{
preloader = new createjs.LoadQueue(true);
preloader.addEventListener("complete",this.handleComplete.bind(this));
var manifest = [
{src:"./images/yourIMAGE.PNG"},
];
preloader.loadManifest(manifest);
};
handleComplete = function()
{
console.log("Load complete!");
//other function
};
}
This is a way to do it. If you have questions just let me know.

Related

react-native-video doesn't load videos with a dynamic uri

I'm working on an app where one part of the process is shooting a video, then uploading it. I'm using react-native-video to display the preview after the user has finished recording, and react-native-camera for the capturing process. I also use react-navigation to move between screens.
Currently I can get to the preview screen and set the video component's source uri from Redux. However, there is no player to be seen. The uri is in format "file:///path/video.mp4", so apparently it should be in the app cache as intended.
First the user is presented with a camera, where s/he can capture the video.
const recordVideo = async () => {
if (camera) {
const data = await camera.current.recordAsync()
if (data) {
dispatch(saveVideo(data)) <-- CONTAINS THE URI
navigation.navigate(CONFIRM)
}
}
When stopRecording() is called, the promise obviously resolves and the video's URI will be dispatched to Redux. Afterwards we navigate to the "confirmation screen", where the user can preview the video and choose whether to shoot another or go with this one.
My problem is, I can't get that preview video to play at all. I think I've tried pretty much everything within my power by now and I'm getting really tired of something so seemingly simple being so overly difficult to do. I've gotten the video to play a few times for some odd reason, so it's not the player's fault. At best what I've achieved is show the preview once, but when you go back and shoot another, there's no video preview anymore. Also, the "confirm" screen loads photos normally (that were taken in the same manner: camera -> confirm), but when it's the video's turn, it just doesn't work. The video component's onError handler also gives me this: {"error": {"extra": -2147483648, "what": 1}} which seems like just gibberish.
PS. yes, I've read through every related post here without finding a proper solution.
Use Exoplayer
Instead of using the older Media Player on Android, try using the more modern Exoplayer. If you're on React Native 0.60+, you can specify this in your react-native.config.js by doing the following:
module.exports = {
dependencies: {
"react-native-video": {
platforms: {
android: {
sourceDir: "../node_modules/react-native-video/android-exoplayer"
}
}
}
}
};
I was experiencing the same issue and this solution worked for us. Note, we're only supporting Android 5+ so not sure if this will work with devices older than that.
https://github.com/react-native-video/react-native-video/issues/1747#issuecomment-572512595

How to capture an animated View as video

I am using a react-native Image to show some images from some url on the web. Now, based on some condition I update the image urls in different interval.
I want to capture this whole transition into a video file. However, I cannot find a suitable android APIs (for native side) or react-native packages to achieve that.
I already did something similer to convert an android View into a Bitmap and then encode it into a jpeg image.
A basic example of what I already have is as follows:
componentDidMount() {
setInterval(() => {
this.setState({imgUrl: 'some new url' });
}, 2000);
}
render() {
return {
<View style={styles.mystyle}><Image source={this.state.imgUrl}><View>
}
}
Please help me out here. Thanks in advance.
This could help : https://github.com/ycswaves/react-native-screen-recorder
I've not tried this myself, just came across while doing a google search
Possible duplicate question : Is there any plugins for recording screen and voice in React Native with iOS

Android, Xamarin: Load Pictures Into Recycle Viewer While Scrolling

Have you ever been going through apps like 9gag, Instagram or Facebook? You notice, that while scrolling the pictures load into the recviewer. They sort of come in one by one while you can still use the app.
I have implemented my own custom recviewer and am stuck right here:
pictures = KumulosHelper.Pictures.getNewestXPhotosFromUserInRange
(strUsername, "6", startNumberOfTask.ToString(), "1");
foreach (var picture in pictures)
{
startNumberOfTask++;
var metrics = Resources.DisplayMetrics;
lstData.Add(new DataForProfile()
{
imageId = startNumberOfTask,
img = (Bitmap.CreateScaledBitmap
(KumulosGeneral.DecodePhotoFromBase64(picture.photo),
metrics.WidthPixels, metrics.WidthPixels, true)),
description = picture.taskId.ToString()
});
}
Where I type in "6" is where I get 6 pictures to load into my recycle viewer form the server. I can type in 10 or 20 and it continues loading those pictures. So, I could probably set up a "reachedbottomevent" to continue loading new pictures when the viewer reached the end. But that would mean that the user has to wait everytime he or she reached the bottom of the matrix. This is pretty annoying. Also, the whole activity wont start untill all pictures are fully loaded.
How do I get my recview to behave like the afforementioned apps above? Some sort of "smart" loading the pictures?
Thank you for the input!
Try using the Picasso library which is very reliable and easy to use. It also loads pictures in a background thread.
https://www.nuget.org/packages/Square.Picasso/
Also, the whole activity won't start until all pictures are fully loaded.
In order not to block your UI thread try using a BackgroundWorker or a Task.
At last, if you want to load a new batch of images before the user reaches the bottom of your list, then change your logic to trigger the call for a new batch for example when the user scrolls half the table.

Progressdialog for phonegap projects

I am very new to html5, css and javascript. i have knowledge in android development.
Now i have started working on phonegap projects.
In my project i want show a loader just like a progressdialog in android when application moves from one screen to another screen or loading something.
Can any one help me to do this in html5?
I had similar need . I was able to do it using navigator object. Please find below sample code
to load data in background
function someJSFunctionLoadingData() {
navigator.notification.activityStart("Your message....", "loading");
////// some activity
navigator.notification.activityStop();
}
Further to navigate around you could use introduce a small delay ( 2 secs) and let progress bar load during that time and then direct user to the url you need. Below is the example for same
function loadMyUrl(){
navigator.notification.activityStart("Loading some url....", "loading");
setTimeout(function loadMyUrl(){
navigator.app.loadUrl('file:///android_asse/www/someurl.html');
navigator.notification.activityStop();
}, 2000 );
}
I got above idea from this link
An easy solution would be to just create a css based spinner element and set it to hidden/visible when needed via your js.
I searched and found tons of examples online here is one for example.

Sound playing and forward swiping animation flickering problem in android phonegap and jqtouch?

I am developing an app using phonegap for android. It consists of around 25 images and similar number of mp3 files. Each mp3 file has duration not more than 10 seconds. The requirement of app is whenever a image is shown on screen its related mp3 file should be played. I am using jqtouch swipe action to move from one page to another. I am facing following problems both on emulator and real device(samsung galaxy 3)-
After 15-20 images sound stops playing both on emulator and galaxy 3. In logcat I got following error
ERROR/AudioFlinger(34): not enough memory for AudioTrack size=49216
I am using following code to play mp3 files
if(mp3file!=null){
mp3file.stop();
mp3file = null;
}
mp3file = new Media("/android_asset/www/name_of_file.mp3",
function() {
console.log("playAudio():Audio Success");
},
function(err) {
},
function(status) {
});
mp3file.play();
I think error is due to audiomanager objects from phonegap api of each mp3 file remaining in memory.
I want to know how to destroy media object created in javascript. You can play, stop, pause. But is there any method in phonegap for android to destroy it so that it does not remain in memory after it has done playing.
Another problem that I am facing is related with left swipe action in jqtouch to view next image. If I am currently viewing image1 and if I try to view image2 by left swipe action, image2 is shown for short amount of time and after that image1 is shown for a moment and after that again image2 is shown. In short the transition from image1 to
image2 is not smooth and it has flickering effects. However if i go from image2 to image1 using right swipe transition is smooth.
Thanks
I got some help with another developer on this.The trick is to make a function declare mp3file outside the function then call stopRecord() on it.(even though you're not doing recording).I tested this with a simple button playing the sound over and over and it worked 75 times before I got tired of playing with it.
Let me know it works for you.
var mp3file;
function playAudio(){
if(mp3file!=null){
mp3file.stop();
mp3file.stopRecord();
mp3file=null;
}
mp3file = new Media("/android_asset/www/yourmp3.mp3",
function() {
console.log("playAudio():Audio Success");
},
function(err) {
},
function(status) {
});
mp3file.play();
}

Categories

Resources