Flex:将 VideoPlayer.currentTime 转换为字符串“00:00:00:000”
这个怎么样:
我想将flex内的videoPlayer组件显示的currentTime格式化,例如:8230.999到01:59:59:999,即“小时:分钟:秒:毫秒”
我尝试了不同的代码集,但它们无法使其工作,因为 currentTime 也不是正确的毫秒时间,因为它在秒中添加了一个浮动的 3 位数字点;
所以不是: 2000ms 它输出 2.000
像我这样的人无法理解!
感谢您的帮助:)
### UPDATE我仍然有毫秒的问题。 这是当前的 MXML:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function convert_clickHandler(event:MouseEvent):void
{
var val:Number = new Number(inPut.text); //inPut.text = 1000.001
//val = val * 1000;
outPut.text = timeFormat(val);
}
public static function timeFormat(value:Number):String
{
var milliseconds:Number = value % 1000;
var seconds:Number = Math.floor((value/1000) % 60);
var minutes:Number = Math.floor((value/60000) % 60);
var hours:Number = Math.floor((value/3600000) % 24);
var s_miliseconds:String = (milliseconds<10 ? "00" : (milliseconds<100 ? "0" : ""))+ String(milliseconds);
var s_seconds:String = seconds < 10 ? "0" + String(seconds) : String(seconds);
var s_minutes:String = minutes < 10 ? "0" + String(minutes) : String(minutes);
var s_hours:String = hours < 10 ? "0" + String(hours) : String(hours);
return s_hours + ":" + s_minutes + ":" + s_seconds + '.'+s_miliseconds;
// returns 00:00:01.000.0009999999999763531 should return 00:00:01.001
// I still have problem with milliseconds
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput x="240" y="72" id="inPut" text="1000.001"/>
<s:TextInput x="240" y="140" id="outPut"/>
<s:Button x="274" y="107" label="convert" id="convert" click="convert_clickHandler(event)"/>
</s:Application>
what about this one:
I want to format the currentTime displayed by a videoPlayer component inside flex, something like : 8230.999 to something like 01:59:59:999 which is "hours:minutes:seconds:milliseconds"
I trie different sets of codes but they can't get it to work because currentTime is nor a correct miliseconds time as it adds a floating 3 digit point to seconds;
so instead of : 2000ms it outputs 2.000
something people like me just can't understand!
thanx for any help :)
### UPDATE
I still have problem with milliseconds.
here's the current MXML:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
protected function convert_clickHandler(event:MouseEvent):void
{
var val:Number = new Number(inPut.text); //inPut.text = 1000.001
//val = val * 1000;
outPut.text = timeFormat(val);
}
public static function timeFormat(value:Number):String
{
var milliseconds:Number = value % 1000;
var seconds:Number = Math.floor((value/1000) % 60);
var minutes:Number = Math.floor((value/60000) % 60);
var hours:Number = Math.floor((value/3600000) % 24);
var s_miliseconds:String = (milliseconds<10 ? "00" : (milliseconds<100 ? "0" : ""))+ String(milliseconds);
var s_seconds:String = seconds < 10 ? "0" + String(seconds) : String(seconds);
var s_minutes:String = minutes < 10 ? "0" + String(minutes) : String(minutes);
var s_hours:String = hours < 10 ? "0" + String(hours) : String(hours);
return s_hours + ":" + s_minutes + ":" + s_seconds + '.'+s_miliseconds;
// returns 00:00:01.000.0009999999999763531 should return 00:00:01.001
// I still have problem with milliseconds
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextInput x="240" y="72" id="inPut" text="1000.001"/>
<s:TextInput x="240" y="140" id="outPut"/>
<s:Button x="274" y="107" label="convert" id="convert" click="convert_clickHandler(event)"/>
</s:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
感谢 Glycerine 和 Zaren 并结合他们的建议,我想出了这个课程:
我这样使用它:
希望它对其他人有帮助。再次感谢大家的支持;-)
Thanx to the help of both Glycerine and Zaren and by combining their suggestions, I come up with this class:
I use it like this:
Hope it helps someone else. Again, Thank you guys for your support ;-)
正确的一个:
这是我做的。一个完整的班级。
这有效 - 谷歌搜索它。
A correct one:
I made this one. A complete class.
this works - Googled it.
我倾向于使用日期格式化程序来生成正确的输出...
我希望这对您有所帮助。
I tend to use a Date formatter to generate the proper output...
I hope that helps you out.
我需要将“00:02:31:76”这样的字符串转换为秒数。如果有人感兴趣,这是该类:
package {
}
然后,如果我想使用它,我可以调用,例如:
跟踪(ConvertStringToTime.processTimeString(“00:02:03:25”));
I needed to convert a string like "00:02:31:76" to a number of seconds. If anyone is interested, here's the class for that:
package {
}
Then, if I want to use it, I can call, for example:
trace(ConvertStringToTime.processTimeString("00:02:03:25"));
为什么不在这里:
Why not this here: