I am trying to load a very short .mp3 file in my preload() function like this:
game.load.audio('sword', '$assetPath/swordraw.mp3', true);
As soon as this code gets executed, it crashes with the error
Breaking on exception: Invalid arguments(s)
pointing to a console.warn in Phaser's Loader's fileError function which is as below:
fileError(int index) {
this._fileList[index]['loaded'] = true;
this._fileList[index]['error'] = true;
this.onFileError.dispatch([this._fileList[index]['key'], this._fileList[index]]);
window.console.warn("Phaser.Loader error loading file: "
+ this._fileList[index]['key'] + ' from URL ' + this._fileList[index]['url']);
this.nextFile(index, false);
}
Through the debugger of DartEditor I have seen that for some reason _fileList[10]['url'] (URL for audio file) is picked up as being null here, and that is the cause of the exception (can't concat. null to a string) but why is url null?
I've checked the obvious: the file name is correct and assetPath is certainly initialised correctly since all the other files (which are images) before this load fine. So this seems like an audio file issue of some kind but I can't see what the problem is.
Oh, seems like I found the offender here... https://github.com/playif/play_phaser/blob/ae6a08e5a6eb159149fac01e5831fd8572223a44/lib/loader/loader.dart#L1447
When the Loader is setting up stuff about a newly added file it calls this getAudioUrl if the file is an audio file...
getAudioURL(urls) {
//String extension;
if (urls is String) {
urls = [urls];
}
for (var i = 0; i < urls.length; i++) {
var url = urls[i];
//extension = urls[i].toLowerCase();
//extension = extension.substr((Math.max(0, extension.lastIndexOf(".")) || Infinity) + 1);
if (this.game.device.canPlayAudio(url.split('.').last)) {
//return urls[i];
return url;
}
}
return null;
}
...and as you may gather from the above, the method will return null seemingly if the device cannot play the the type of file supplied. So then, Dartium can't play .mp3s?
Related
string mediafile;
mediafile=Constants.AudioLink;
NSUrl url1=new NSUrl(mediafile);
var audioplayer=AVAudioPlayer.FromUrl(url1);
URL is getting link correctly but audio player getting value null. It throws an exception below:
Could not initialize an instance of the type 'AVFoundation.AVAudioPlayer': the native 'initWithContentsOfURL:error:' method returned nil.
It is possible to ignore this condition by setting : MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false
What can i do, Please give me the solution.
These is a really quick example of loading/playing an .mp3 file that has a build type of BundledResource (I dropped into the Resources folder of the project) and thus is placed in the app's root directory).
I do a quick check via AudioToolbox.AudioSource.Open to make sure the file exists, can be read, and is a valid media file type so I know that AVAudioPlayer will not throw a fatal error trying to load it.
AVAudioPlayer player; // Class level object ref
partial void playButtonTouch (UIButton sender)
{
if (player != null && player.Playing)
player.Stop ();
else {
var mp3File = "WildTurkeysEN-US.mp3";
var mp3URL = new NSUrl (mp3File);
Console.WriteLine (mp3URL.AbsoluteUrl);
var mp3 = AudioToolbox.AudioSource.Open (mp3URL, AudioFilePermission.Read, AudioFileType.MP3);
if (mp3 != null) {
Console.WriteLine (mp3.EstimatedDuration);
player = AVAudioPlayer.FromUrl (mp3URL);
player.Play ();
} else {
Console.WriteLine ( "File could not be loaded: {0}", mp3URL.FilePathUrl );
}
}
}
I'm trying out Dart for the first time and I can't get the error handling to work for me. Here's some information about it.
Resources:
Gist with HTML, CSS and Dart: gist.github.com/enjikaka/8164610
ZIP with the project: ge.tt/6StW4cB1/v/0?c
JavaScript version on CodePen: codepen.io/enjikaka/pen/giurk
How I want it:
Making an instance of MinecraftSkin should throw an StateError if the image source returns a 403 error code. The exception should be handled in the generateHead() function where the instance of MineCraft skin is attempted to be made.
How it is:
If an image representing the skin of a MineCraft player does not exist (when the image source does not exist and returns 403) the code stops on line 22 (onError; where I throw the StateError) and prints to console "Breaking on exception: Bad state: User has no skin".
However, in the catch on generateHead, nothing gets executed. It doesn't print the StateError message when I prompt it to, neither does it insert the StateError message to the selected element in the DOM.
Code
import 'dart:html';
class MinecraftSkin {
String user;
CanvasElement ce = new CanvasElement();
void _generateCanvas(Event e) {
CanvasRenderingContext2D ctx = ce.getContext('2d');
ctx.imageSmoothingEnabled = false;
ctx.drawImageScaledFromSource((e.target as ImageElement),8,8,8,8,0,0,ce.width,ce.height);
}
CanvasImageSource getHead() => ce;
String name() => user;
MinecraftSkin(String minecraftUser, num size) {
user = (minecraftUser == null) ? 'Notch' : minecraftUser;
ce.width = size;
ce.height = size;
ImageElement img = new ImageElement()
..onLoad.listen(_generateCanvas)
..onError.listen((_) => throw new StateError('User has no skin'));
img.src = "http://s3.amazonaws.com/MinecraftSkins/"+user+".png";
}
}
void generateHead(Event e) {
MinecraftSkin ms;
try {
ms = new MinecraftSkin((querySelector('#userName') as InputElement).value, 128);
} on StateError catch(se) {
print(se.message);
querySelector('#status').text = se.message;
}
CanvasElement cems = ms.getHead();
cems.id = "mc" + ms.name();
cems.title = "mc" + ms.name();
document.body.append(cems);
querySelector('#status').text = "Got head!";
}
void main() {
querySelector('#generateHead').onClick.listen(generateHead);
}
Thanks in advance!
Sincerely, Jeremy
The image listeners (onLoad, onError) are asynchronous. The MincraftSkin instantiation is completed without any errors, and only after the image resource is loaded or an error is received, is the StateError thrown, probably several hundred milliseconds later. The constructor does not wait around to see if the image will properly load or not.
i get thumbnail image using fileconnection.
I get image using thread constructor. I pass the url and get image.
If the two image url are same , i got exception "FileIOException: File already exists "
My code is here.,
FileConnection fConn = null;
try
{
String fileString = MD5.encodeStringMD5(url);
fConn = (FileConnection) Connector.open(fileTempPath+fileString+".png");
if(!fConn.exists())
{
fConn.create();
GetImageFromURL(url,fConn,id);
}
else
{
GetImageFromFolder(fConn, id);
}
fConn.close();
}
catch (Exception e)
{
System.out.println("------"+e);
}
If the urls are differ. No problem occur. But if two or three url r same , Only one image only stored and load on screen. others same url not displaying.
After stored on device memory, its loadding all image.
The Exception throws in this line - "fConn.create();"
Before creating a new file, try to open a file with the same name/path. If it already exists remove it.
If file already exits then do like this:
if(!fConn.exists())
{
fConn.create();
GetImageFromURL(url,fConn,id);
}
else
{
fConn.truncate();//it removes the data in that file;
GetImageFromFolder(url,fConn, id);
}
I have list of URL in txt file I am using it for performance test, since URL were not formed correctly java.IO.exeption were thrown,I would like to know how to check correctness of URL? and whether it is working fine? I have more than 35 K url checking manually will consume lot's of time.
To check whether URL are properly formed try casting the string to an URI object.
eg:
public void validURLs(List<string> urlList)
{
int line = 1;
for(string s : urlList)
{
try
{
URI test = new URI(s);
}
catch(Exception e)
{
System.err.println(s + " is not a valid URL, item " + line);
}
line ++;
}
}
i am using the following code to show the image that has been saved in my database from my asp.net mvc(C#) application:.
public ActionResult GetSiteHeaderLogo()
{
SiteHeader _siteHeader = new SiteHeader();
Image imgImage = null;
long userId = Utility.GetUserIdFromSession();
if (userId > 0)
{
_siteHeader = this.siteBLL.GetSiteHeaderLogo(userId);
if (_siteHeader.Logo != null && _siteHeader.Logo.Length > 0)
{
byte[] _imageBytes = _siteHeader.Logo;
if (_imageBytes != null)
{
using (System.IO.MemoryStream imageStream = new System.IO.MemoryStream(_imageBytes))
{
imgImage = Image.FromStream(imageStream);
}
}
string sFileExtension = _siteHeader.FileName.Substring(_siteHeader.FileName.IndexOf('.') + 1,
_siteHeader.FileName.Length - (_siteHeader.FileName.IndexOf('.') + 1));
Response.ContentType = Utility.GetContentTypeByExtension(sFileExtension.ToLower());
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BufferOutput = false;
if (imgImage != null)
{
ImageFormat _imageFormat = Utility.GetImageFormat(sFileExtension.ToLower());
imgImage.Save(Response.OutputStream, _imageFormat);
imgImage.Dispose();
}
}
}
return new EmptyResult();
}
It works fine when i upload original image. But when i upload any downloaded images, it throws the following error:
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(Stream stream, ImageFormat format)
For. Ex: When i upload the original image, it shows as logo in my site and i downloaded that logo from the site and when i re-upload the same downloaded image, it throws the above error. It seems very weird to me and not able to find why its happening. Any ideas on this?
I'd guess that your problem lies here:
using (System.IO.MemoryStream imageStream = new System.IO.MemoryStream(_imageBytes))
{
imgImage = Image.FromStream(imageStream);
}
Because after using .FromStream, the Image owns the stream and might be very upset if you close it. To verify if that's the problem you can just try:
using (System.IO.MemoryStream imageStream = new System.IO.MemoryStream(_imageBytes))
{
imgImage = new Bitmap( Image.FromStream(imageStream) );
}
I've found that error usually comes from a file access problem. Sounds obvious, I realize, but double-check that the file path is correct and that the file exists, and also that the IIS process has permissions to that file.