忍者ブログ
Flex,Java,Html など、調べた事のメモ帳です。 間違ってたらゴメンなさい。
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ファイルのコピーは java.io.File では出来ません。自分で Stream を開いて、 入力から出力へデータを流し込む必要があります。


ソース記述例

public static void copy(File from, File to) throws IOException {
  BufferedOutputStream out = null;
  BufferedInputStream in = null;
  try {
    in = new BufferedInputStream(new FileInputStream(from));
    out = new BufferedOutputStream(new FileOutputStream(to));
    byte[] buff = new byte[4096];
    int len = 0;
    while ((len = in.read(buff, 0, buff.length)) >= 0) {
      out.write(buff, 0, len);
    }
  } finally {
    if (in != null) {
      try {
        in.close();
      } catch (IOException e) {
      }
    }
    if (out != null) {
      try {
        out.close();
      } catch (IOException e) {
      }
    }
  }
}
 



サウンドのロード処理の監視


サウンドファイルが非常に大きくて、ロードに時間がかかることがあります。サウンドが完全にロードされる前に、Flash Player および AIR でアプリケーションからそのサウンドを再生する場合、ロード済みになったサウンドデータの量および既に再生されたサウンドデータの量をユーザーに示すことができます。

Sound クラスは、サウンドのロードの進行状況を比較的簡単に表示できるようにする、ProgressEvent.PROGRESS および Event.COMPLETE という 2 つのイベントを送出します。次の例は、これらのイベントを使用して、サウンドのロードの進行状況に関する情報を表示する方法を示しています。



import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.net.URLRequest;

var s:Sound = new Sound();
s.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
s.addEventListener(Event.COMPLETE, onLoadComplete);
s.addEventListener(IOErrorEvent.IO_ERROR, onIOError);

var req:URLRequest = new URLRequest("bigSound.mp3");
s.load(req);

function onLoadProgress(event:ProgressEvent):void
{
    var loadedPct:uint = Math.round(100 * (event.bytesLoaded / event.bytesTotal));
    trace("The sound is " + loadedPct + "% loaded.");
}

function onLoadComplete(event:Event):void
{
    var localSound:Sound = event.target as Sound;
    localSound.play();
}
function onIOError(event:IOErrorEvent)
{
    trace("The sound could not be loaded: " + event.text);
}
 
Flex4 の場合
  FlexGlobals.topLevelApplication.stage.displayState = StageDisplayState.FULL_SCREEN;

Flex3 の場合
  Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;


Flash Player のフルスクリーンモードの有効化

HTML ページに埋め込まれた SWF ファイルでフルスクリーンモードを有効にするには、Flash Player を埋め込む HTML コードに param タグを含め、次のように embed 属性で名前 allowFullScreen と値 true を指定する必要があります。

<object> 
    ... 
    <param name="allowFullScreen" value="true" /> 
    <embed ... allowfullscreen="true" /> 
</object>

ロードしたサウンドの再生は、次のようにして Sound オブジェクトの Sound.play() メソッドを呼び出すことで簡単に実行できます。

var snd:Sound = new Sound(new URLRequest("smallSound.mp3"));
snd.play();

ActionScript 3.0 を使用してサウンドを再生する場合、次の操作を実行できます。

  • 特定の開始位置からサウンドを再生する
  • サウンドを一時停止し、後で同じ位置から再生を再開する
  • サウンドの再生がいつ終了するかを正確に把握する
  • サウンドの再生の進行状況を追跡する
  • サウンドの再生中にボリュームまたはパンを変更する


基本的には Integer#toHexString(byte) を利用するのですが、 Java の byte 型は符号付の為、 全て正の値に直さなくてはいけません。

ソース記述例


public static void main(String[] args) {
    String str = "hoge-あ";
    byte[] arr = str.getBytes();
    for (int i = 0; i < arr.length; i++) {
        System.out.println(Integer.toHexString(arr[i] & 0xff));
    }
}

を実行すると



出力結果

68
6f
67
65
2d
82
a0

また、sun.misc パッケージの HexDumpEncoder を使う方法もあります。


ソース記述例


public static void main(String[] args) {
    String str = "hoge-あ";
    HexDumpEncoder enc = new HexDumpEncoder();
    System.out.println(enc.encode(str.getBytes()));
}

を実行すると


出力結果

0000: 68 6F 67 65 2D 82 A0



前のページ      次のページ
ブログランキング
にほんブログ村 IT技術ブログ IT技術メモへ
 
カレンダー
09 2025/10 11
S M T W T F S
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
人気ブログランキング
ブログランキング ブログランキング
最新TB
ブログ内検索
PR
ATOM  
ATOM 
RSS  
RSS 
Copyright ©   プログラムメモ   All Rights Reserved
Design by MMIT  Powered by NINJA TOOLS
忍者ブログ [PR]