I wrote a game in flex and that game has sound. I load the sound from an asset like this to play the sound file, this is the function:
public function playSound(value:String, vol:Number):void
{
mySound=new Sound();
var urlRequest:URLRequest=new URLRequest(value);
mySound.load(urlRequest);
sChannel=mySound.play(0, 0, new SoundTransform(vol, 0));
}
When I'd like to play the sound I call it like this:
playSound("sounds/abc.mp3", 1)
The "sounds" in the package in the current project. It works fine when I build in eclipse, but when I put that game on the web, I can't hear the music.
Could anyone tell me how to fix please
Have you ever tried to modified your sound file by
Remove all metadata in the sound file.
Export it to a new MP3 file.
Is it too large to load? Try to add error event to listen.
var urlRequest:URLRequest=new URLRequest(value);
You're passing this a relative path, so when it's running on a remote machine it's looking there for the sound and obviously not finding it. You need to embed the sound, as detailed in this question:
[Embed(source="myfile.mp3")]
[Bindable] //Not required. Just an example of using multiple meta tags.
public var soundCls:Class;
Then, I'm a bit rusty, but I believe it's
sChannel = new soundCls().play(0, 0, new SoundTransform(vol, 0));
Just try this.
var urlReq:URLRequest = new URLRequest("assets/sound/sound3.mp3");
var sound:Sound= new Sound(urlReq);
sound.play();
Related
this seems pretty specific to ask - but there was no other alternative to the expertbase of stackoverflow!
I'm stuck in a problem where I need to control the radius of the circle by an external means such as a dropdown or a textbox.
I had a hard time doing the circle and had to copy stuff from the Twitter search example on:
http://code.google.com/apis/maps/articles/mvcfun/twittersearch.html
Ideally, I would like to know how to bind an external even to the radiusWidget, the problem is - the sizer inside the radiusWidget seems a private entity.
It would be awesome if someone could hit me in the face with a bang!
Thx
distanceWidget.set('distance', XXX) should work. If you read the MVC article you can see how the binding is bi-directional.
You can look at the source of the Twitter example by downloading it to your computer, as you likely already did. When you have the source you can adapt it to your purposes as you like. The software usage rights (terms of usage, license, etc), if they are any, have to be respected of course.
In the case of the RadiusWidget you would just do:
function RadiusWidget(opt_distance) {
// ...
this.sizer = this.addSizer_(); // sizer is now accessible in RadiusWidget
}
RadiusWidget.prototype.addSizer_ = function() {
var sizer = ...
// ...
return sizer;
}
I need to read the dimensions of a given video file (its width and height), without constructing a video player, like Phonon, e.g. My question is which class I should use to get access to this data. I have already tried using QPixmap and QMovie, but niether of them supports *.mov.
Thank you!
Pavlo, you can try this:
QMediaContent media("myMovie.mov");
QSize resolution = media.canonicalResource().resolution();
The code uses QMediaResource class from Qt Mobility project. I haven't tried it yet and I suppose you need at least a correct backend (plugin that is capable of reading MOV format). I'm giving this answer only from API overview.
Hope this helps.
I finally solved my problem and I thought I'd share my solution with everybody else.
In the class constructor I initialize the following two variables:
media = new Phonon::MediaObject(this);
videoWidget = new Phonon::VideoWidget;
I connect a signal of media to a slot in my class:
connect(media,SIGNAL(stateChanged(Phonon::State,Phonon::State)),
this,SLOT(videoState(Phonon::State,Phonon::State)));
I let the user choose a video file:
QString filename = QFileDialog::getOpenFileName(this,tr("Choose video file"),QDir().homePath(),tr("Video files (*.mov *.mpg *.avi)"));
And apply this file to the media object:
media->setCurrentSource(filename);
Phonon::createPath(media,videoWidget);
Because media object is already connected to a slot, every change in media can be monitored with its help.
void VideoModuleDialog::videoState(Phonon::State newState, Phonon::State oldState)
{
if(newState == Phonon::PlayingState || newState == Phonon::StoppedState)
{
width->setText(QString().number(videoWidget->sizeHint().width()));
height->setText(QString().number(videoWidget->sizeHint().height()));
}
if(newState == Phonon::ErrorState)
{
QMessageBox::critical(this,tr("Video file error!"),
tr("Video file error: ") + media->errorString(),QMessageBox::Ok);
}
}
I must admit, however, that this code seems to me to be quite slow. Phonon library is used in my program only in one place, and this is here, in a dialog window where user can choose a video clip to embed, and i want the video dimensions to be read from file. It takes some time until this dialog window opens, so I guess, this solution is a bit too harsh for my problem. However, I was not able to find another solution. If there are different opinions as to the subject of this post, I'd be glad to hear them.
How does one create an array of loaders?
The bigger picture:
I have written a mapping program in flex. I want to change my mapping program so that all I need to do is drop in a new xml file instead of going into my flex file and adding the exact number of item loaders I need. So I guess I'm looking for an array of loaders that can load the image files that are within my XML file.
xml file example:
<locations>
<location>
<name>Big Star</name>
<street>123 Some St.</street>
<city>City</city>
<state>XX</state>
<zip>555555</zip>
<lat>12.34567</lat>
<long>-67.54321</long>
<iconFile>bigStar_icon.gif</iconFile>
<imageFile>bigStar_img.swf</imageFile>
<motion>no</motion>
<featured>yes</featured>
<category>Grocery</category>
</location>
</locations>
this xml can sometimes have 2000 locations.
Yeah, that's a pretty bad question. Literally (if facetiously):
var loaders:Array = [new Loader(), new Loader()];
Trying to read into what you asked, it sounds like you are trying to load up a whole bunch of stuff and handle them all loading together somehow... and if you have to ask, you're going to struggle.
You could try using the Bulk Loader library though, which does this for you reasonably well. There are probably others.
Not a direct answer to the question since it's a bit vague + #alecmce already gave an answer (I would go for a loader queue such as BulkLoader in this situation as well).
However, since I noticed a similar question some time ago I just wanted to point out that instantiating all the loaders at once just feels a bit wrong.
Wouldn't it be a bit appropriate to just store the urls and handle process them one by one ?
Basic example :
(beware I typed it in without testing...)
// So here's the point: only Strings are stored ...
var urls:Array = new Array('image1.jpg','image2.jpg',image3.jpg);
loadNext();
function loadNext()
{
if(urls.length() == 0)
return;
load(urls.shift())
}
function load(url:String):void
{
// The loader is created lazily just before before we need it
var loader:Loader = new Loader(new URLRequest(url));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded)
loader.load(url);
}
function onLoaded(e:Event):void
{
event.target.removeEventListener(Event.COMPLETE, onLoaded);
addChild(event.target.content); // ... or whatever has to happen here.
loadNext();
}
I'm using the VideoDisplay to play flv's, mov's, and mp4's and everything is working great. They are all being loaded via progressive download and are not being streamed. What I'd like to do is to grab a single specified frame (like whatever is being shown at the 10 second mark), convert it to a bitmap and use that bitmap as the preview image for the video. I'd like to do this at runtime so I don't have to create a preview image for every video that would be shown.
Any idea's on how to do this? I'd rather not fake it by playing it - seeking for that specific frame and then pausing it but I may have no other choice?
Ryan and James are correct -- the right way's probably to extract frames at upload/transcode-time. But if that's not an option, you could opt for using some sort of a default/placeholder image of your own (something generic or somehow suitable for all videos whose thumbs haven't yet been captured), and just use VideoDisplay's DisplayObject-ness to grab and then upload a frame to your server, e.g.:
<mx:Script>
<![CDATA[
var captured:Boolean;
private function creationCompleteHandler(event:Event):void
{
videoDisplay.source = "http://yourserver/yourvideo.flv";
}
private function videoDisplay_playheadUpdate(event:VideoEvent):void
{
if (!captured && videoDisplay.playheadTime >= 10)
capture();
}
private function capture():void
{
var bmpData:BitmapData = new BitmapData(videoDisplay.width, videoDisplay.height);
bmpData.draw(videoDisplay);
captured = true;
// Now just upload the byte array to your server for the next user
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.BINARY;
// ... etc.
}
]]>
</mx:Script>
<mx:VideoDisplay id="videoDisplay" playheadUpdate="videoDisplay_playheadUpdate(event)" />
Again, it's perhaps not the most elegant solution, but it certainly works. This way, the first user sees the generic image, but every user thereafter gets the generated thumbnail. (Which, of course, you'll have uploaded and properly associated by then.) Make sense?
I'm pretty sure this isn't possible. It may well be... but don't think so. I think the only way to load in video is to use the NetStream and NetConnection object, which as you know just kicks off the loading of the video.
If this is user generated video i think the best bet is to have some serever side script that generates the preview image. Have no idea how this is done but think this is how most clip sites work.
If all the videos are in your control it may be possible to write a script for one of the video editing programs to automate generating the image for a specific frame from a list of files. I think this is probably your best route as alternative that you could get up and running quickly.
Sorry for the vague answer... it may point you in the right direction if you need a quick solution.
I agree with James, the only way to really do this would be to do it with a server side script and pull certain frames out of the video. Even if you could do this with flex, you really would not want to put the burden to do this (which would be processor intensive I would think) on the client machine. Not to mention it will be much more efficient to create the image before hand than to have flex determine the thumbnail to show every time it is loaded.
Is it possible to generate PDF Documents in an Adobe AIR application without resorting to a round trip web service for generating the PDF? I've looked at the initial Flex Reports on GoogleCode but it requires a round trip for generating the actual PDF.
Given that AIR is supposed to be the Desktop end for RIAs is there a way to accomplish this? I suspect I am overlooking something but my searches through the documentation don't reveal too much and given the target for AIR I can't believe that it's just something they didn't include.
There's AlivePDF, which is a PDF generation library for ActionScript that should work, it was made just for the situation you describe.
Just added a Adobe Air + Javascript + AlivePDF demo:
This demo doesn't require flex and is pretty straight forward.
http://www.drybydesign.com/2010/02/26/adobe-air-alivepdf-without-flex/
One of the other teams where I work is working on a Flex-based drawing application and they were totally surprised that AIR / Flex does not have PDF authoring built-in. They ended up rolling their own simple PDF creator based on the PDF specification.
Yes it is very easy to create PDF using AlivePDF, here is the sample code, first method create a pdf and second method save the pdf on disk and return the path, feel free to ask any question.
public function createFlexPdf() : String
{
pdf = new PDF();
pdf.setDisplayMode (Display.FULL_WIDTH,Layout.ONE_COLUMN,Mode.FIT_TO_PAGE,0.96);
pdf.setViewerPreferences(ToolBar.SHOW,MenuBar.HIDE,WindowUI.SHOW,FitWindow.RESIZED,CenterWindow.CENTERED);
pdf.addPage();
var myFontStyle:IFont = new CoreFont ( FontFamily.COURIER );
pdf.setFont(myFontStyle,10);
pdf.addText('Kamran Aslam',10,20);//String, X-Coord, Y-Coord
return savePDF();
}
private function savePDF():String
{
var fileStream:FileStream = new FileStream();
var file:File = File.createTempDirectory();
file = file.resolvePath("temp.pdf");
fileStream.open(file, FileMode.WRITE);
var bytes:ByteArray = pdf.save(Method.LOCAL);
fileStream.writeBytes(bytes);
fileStream.close();
return file.url;
}