Tag Archive for media

Simplify Flow Between Screens with the “Scene System”

package com.michaeljameswilliams.gamedev.gamescenes
{

/**
* Based on <a href="http://www.rivermanmedia.com/programming/6-object-oriented-game-programming-the-scene-system" >http://www.rivermanmedia.com/programming/6-object-oriented-game-programming-the-scene-system</a>
* More info: <a href="http://gamedev.michaeljameswilliams.com/2009/04/13/as3-scene-system/" >http://gamedev.michaeljameswilliams.com/2009/04/13/as3-scene-system/</a>
* @author MichaelJWilliams
*/

public interface IGameScene
{
/**
* Update logic for this game scene.
*/
function update():void;
/**
* Redraw everything on screen.
*/
function redraw():void;
/**
* Load all of the data and graphics that this scene needs to function.
*/
function load():void;
/**
* Unload everything that the garbage collector won't unload itself, including graphics.
*/
function unload():void;
}

}

package com.michaeljameswilliams.gamedev.gamescenes
{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;

/**
* Based on <a href="http://www.rivermanmedia.com/programming/6-object-oriented-game-programming-the-scene-system" >http://www.rivermanmedia.com/programming/6-object-oriented-game-programming-the-scene-system</a>
* More info: <a href="http://gamedev.michaeljameswilliams.com/2009/04/13/as3-scene-system/" >http://gamedev.michaeljameswilliams.com/2009/04/13/as3-scene-system/</a>
* Singleton template from here: <a href="http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html" >http://www.gskinner.com/blog/archives/2006/07/as3_singletons.html</a>
* @author MichaelJWilliams
*/

public class GameSceneManager {
private static var _instance:GameSceneManager;
private static var _allowInstantiation:Boolean;
private static var _currentScene:IGameScene;
private static var _sceneContainer:DisplayObjectContainer;

public static function getInstance( p_sceneContainer:DisplayObjectContainer = null ):GameSceneManager
{
if ( _instance == null )
{
_allowInstantiation = true;
_instance = new GameSceneManager();
_allowInstantiation = false;
}

if ( p_sceneContainer )
{
setSceneContainer( p_sceneContainer );
}

return _instance;
}

/**
*
* @param	p_sceneContainer	Object that is parent of each scene -- for example, the document class
*/
public function GameSceneManager():void
{
if ( !_allowInstantiation )
{
throw new Error("Error: Instantiation failed: Use GameSceneManager.getInstance() instead of new.");
}
}

public static function setSceneContainer( p_sceneContainer:DisplayObjectContainer ):void
{
_sceneContainer = p_sceneContainer;
}

/**
* Update logic for the current scene.
*/
public static function update():void
{
_currentScene.update();
}

/**
* Redraw everything on screen.
*/
public static function redraw():void
{
_currentScene.redraw();
}

/**
* A simplified way of loading and unloading scenes
* Notice that the method is static so that anyone can call it.
* @param	p_newScene	The scene to switch to.
*/
public static function changeScene( p_newScene:IGameScene ):void
{
if ( ( p_newScene is DisplayObject ) && ( _sceneContainer ) )
{
if ( _currentScene != null )
{
_sceneContainer.removeChild( _currentScene as DisplayObject );
_currentScene.unload();
}
p_newScene.load();
_currentScene = p_newScene;
_sceneContainer.addChild( _currentScene as DisplayObject );
}
else
{
throw new Error("Error: game scenes must be of type DisplayObject and scene container must be set.");
}
}
}
}

source

Give admins download links for original media

if (Ka.Info.PAGE == 'pages/mediaPlayPage.jsp' &&
(DWRUtil.getValue('userRole') == 'WEBMASTER' || DWRUtil.getValue('userRole') == 'EDITOR')) {
if (Ka.Info.MEDIATYPE == 'VIDEO') {
var links = '<br><a href="'
+ Ka.Info.PATHTOMEDIA
+ '">mp4 format (transcoded)</a><br>';
// KickApps renames the media extension to lower case extension, but Ka.Info retains the case of the original upload
// So we must convert to lower to correct it here
links += '<a href="'
+ Ka.Info.STATICSERVER
+ '/kickapps/images/videos/'
+ Ka.Info.MEDIAID
+ Ka.Info.ORIGVIDEOFORMAT.toLowerCase()
+ '">Original upload</a><br>';
} else if (Ka.Info.MEDIATYPE == 'AUDIO') {
var links = '<br><a href="'
+ Ka.Info.AUDIOPHOTOSERVERPATH
+ Ka.Info.PATHTOMEDIA
+ '">mp3 format</a><br>';
}
document.getElementById("ka_playPageDetails").innerHTML = document.getElementById("ka_playPageDetails").innerHTML + links;
}

source

CSS Media Targeted JavaScript

<div id="mediaInspector"></div>

<style type="text/css">
#mediaInspector {
display:none
}
@media aural {
#mediaInspector { z-index: 1 }
}
@media braille {
#mediaInspector { z-index: 2 }
}
@media embossed {
#mediaInspector { z-index: 3 }
}
@media handheld {
#mediaInspector { z-index: 4 }
}
@media print {
#mediaInspector { z-index: 5 }
}
@media projection {
#mediaInspector { z-index: 6 }
}
@media screen {
#mediaInspector { z-index: 7 }
}
@media tty {
#mediaInspector { z-index: 8 }
}
@media tv {
#mediaInspector { z-index: 9 }
}
</style>

<script type="text/javascript">
var mediaInspector = document.getElementById('mediaInspector');
if (mediaInspector.currentStyle) {
zIndex = mediaInspector.currentStyle['zIndex'];
} else if (window.getComputedStyle) {
zIndex = window.getComputedStyle(mediaInspector, '').getPropertyValue("z-index");
}
switch (parseInt(zIndex)) {
case 1:
// @media aural code
alert('@media aural code');
break;
case 2:
// @media braille code
alert('@media braille code');
break;
case 3:
// @media embossed code
alert('@media embossed code');
break;
case 4:
// @media handheld code
alert('@media handheld code');
break;
case 5:
// @media print code
alert('@media print code');
break;
case 6:
// @media projection code
alert('@media projection code');
break;
case 7:
// @media screen code
alert('@media screen code');
break;
case 8:
// @media tty code
alert('@media tty code');
break;
case 9:
// @media tv code
alert('@media tv code');
break;
}
</script>

source

Generate thumbnail from video

ffmpeg -v 0 -y -i $VIDEOFILE -vframes 1 -ss 4 -vcodec mjpeg -f rawvideo -s 86x60 -aspect 4:3 $THUMBNAILFILE

source

Apache mod_expires for media-files

<ifModule mod_expires.c>
<filesmatch ".(ico|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifModule>

source

Create dynamic css from media field data

css = PAGE
css {
typeNum = 22
config {
additionalHeaders = Content-type: text/css
disableAllHeaderCode = 1
}
stdWrap.required = 1
stdWrap.wrap = |
10 = TEXT
10.value (
.content_header_pic {
)
20 = TEXT
20.data = levelmedia: -1
20.listNum = 0
20.wrap = background: url('uploads/media/|');
30 = TEXT
30.value (
border-top: 8px solid #0D337A;
height: 105px;
width: 100%;
}
)
30.if {
isTrue.data = levelmedia: -1
}
}

[...]

page = PAGE

page {
headerData {
16 = TEXT
16.dataWrap = <link rel="stylesheet" type="text/css" href="index.php?id={field:uid}&type=22" />|
}
}

source

HTML CSS media query

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HTML CSS media queries test</title>
<meta name="keywords" content="css, html, media queries, css3" />
<meta name="description" content="Test CSS 3 media queries dla html" />

<style>

table{ width: 100%}

table td:nth-of-type(1){
background: blue;
color: white;
}

table td:nth-of-type(2){
background: red
}

table td:nth-of-type(3){
background: green;
color: white

}

table td:nth-of-type(4){
background: yellow;
}

@media screen and (max-width: 510px){
table td:nth-of-type(4){
display: none;
}
}

@media screen and (max-width: 383px){
table td:nth-of-type(3){
display: none;
}
}

@media screen and (max-width: 281px){
table td:nth-of-type(1){
display: none;
}
}

</style>
</head>
<body>

<table border="1" summary="ZnikajÄ…ca tabela">
<caption>The znikajÄ…ca tabelka</caption>

<thead>
<tr><th>Ta nie znika</th><td>Znikam przy 281px szerokości</td><td>Nie znikam wogóle</td><td>Znikam przy 384px szerokości</td><td>Znikam przy 510px szerokości</td></tr>
</thead>
<tbody>
<tr><th scope="row">wrwerw</th><td>wewe</td><td>wewrwerwer</td><td>werwer</td><td>werw erwrwrewre</td></tr>
<tr><th scope="row">werwer</th><td>e</td><td>werwrew</td><td>weerwe</td><td>werwrewe</td></tr>

<tr><th scope="row">werwe</th><td>werrrwrerw</td><td>werwer</td><td>werwrwrwrwre</td><td>werwrewe</td></tr>
<tr><th scope="row">wrewerw</th><td>ewrewre</td><td>we</td><td>wwrwer</td><td>rewerwrrwwe</td></tr>
</tbody>
</table>

</body>
</html>

source

get screenshot with mplayer

mplayer media/videos/2008/03/27/the_toss.flv -vf screenshot

source

Media Targeting With CSS Using @Media

@media print {

.class
{
}

}

@media handheld {

.class
{
}

}

@media aural {

.class
{
}

}

source

AS2 CASA ロードした画像をタイル上に並べる

import org.casaframework.load.data.xml.XmlLoad;
import org.casaframework.util.XmlUtil;
import org.casaframework.load.LoadGroup;
import org.casaframework.load.media.MediaLoad;
import org.casaframework.math.geom.Rectangle;
import org.casaframework.layout.DistributionCollection;

var xmlObject:Object;
var myLoadGroup:LoadGroup;
var myXmlLoad:XmlLoad;

loadXmlData();

// XML 読み込み
function loadXmlData(){
trace("xml start");
this.myXmlLoad = new XmlLoad('data/sample.xml'); // xmlのパスを記入
this.myXmlLoad.addEventObserver(this, XmlLoad.EVENT_LOAD_COMPLETE, 'onXmlLoad');
this.myXmlLoad.start();
}

// XML読み込み完了
function onXmlLoad(){
trace("xml load complete");
this.xmlObject = XmlUtil.xmlToObject(this.myXmlLoad.getXml())['data'][0]['block']; // + 〜getXml())['data'][0]['keyword']でxmlのルート-0番目->一番目の要素...と取り出す
init();
}

function init():Void {
myLoadGroup = new LoadGroup();
trace(xmlObject.length);
for (var i:Number = 0; i<xmlObject.length; i++) {
var rect:MovieClip = this.createEmptyMovieClip("rect"+i,getNextHighestDepth());
var holder:MovieClip =rect.createEmptyMovieClip("holder",getNextHighestDepth());
myLoadGroup.addLoad(new MediaLoad(holder,xmlObject[i].img[0].nodeValue)); // ロードする画像のパスの位置
}
myLoadGroup.addEventObserver(this, LoadGroup.EVENT_LOAD_COMPLETE, "onGroupLoadComplete");
myLoadGroup.start();
}

function onGroupLoadComplete(){
trace("全画像ロード完了");
//loading._visible = false;
var _dist:DistributionCollection;
_dist = new DistributionCollection( true );
_dist.setRectangle(new Rectangle(0, 0, 350, Number.POSITIVE_INFINITY));
_dist.setMargin(10, 10, 10, 10);
var thumbs:Array = myLoadGroup.getLoads();
trace(thumbs.length);
for(var i:Number=0;i<thumbs.length;i++){
var mc:MovieClip = thumbs[i].getMovieClip();
//配列に格納される順番が逆転してるのに注意!
trace(thumbs[i].getMovieClip());
//CASA のドキュメントのサンプルはライブラリの中からシンボルを attachMovie してるサンプルなので、
//今回は mc を追加していくだけでOKです。
_dist.addItem(mc);
}
_dist.positionItems();
trace(_dist);
}

source