WWW.oggVorbis 免费音频格式

var oggVorbis : AudioClip

Description描述

Load an Ogg Vorbis file into the audio clip.

加载一个Ogg Vorbis文件到音频剪辑。

If the stream has not been downloaded completely, null will be returned. Use isDone or yield to see if the data is available.

如果流没有被完全下载,将返回null。使用isDone或yield来查看数据是否可用。

Ogg全称应该是OGG Vobis是一种新的音频压缩格式,类似于MP3等现有的音乐格式。但有一点不同的是,它是完全免费、开放和没有专利限制的。OGG Vobis有一个很出众的特点,就是支持多声道,随着它的流行,以后用随身听来听DTS编码的多声道作品将不会是梦想。

Vorbis 是这种音频压缩机制的名字,而Ogg则是一个计划的名字,该计划意图设计一个完全开放性的多媒体系统。目前该计划只实现了OggVorbis这一部分。

Ogg Vorbis文件的扩展名是.OGG。这种文件的设计格式是非常先进的。现在创建的OGG文件可以在未来的任何播放器上播放,因此,这种文件格式可以不断地进行大小和音质的改良,而不影响旧有的编码器或播放器。

参考:AudioClip, AudioSource.

var path = "http://ia301106.us.archive.org/2/items/abird2005-02-10/abird2005-02-10t02.ogg";

function Start () {
	// Start downloading
	//开始下载
	var download = new WWW (path);
	// Wait for download to finish
	//等待下载完成
	yield download;
	// Create ogg vorbis file
	var clip : AudioClip = download.oggVorbis;
	// Play it
	//播放
	if (clip != null) {
		audio.clip = clip;
		audio.Play();
	} else { // Handle error 处理错误
		Debug.Log("Ogg vorbis download failed. (Incorrect link?)");
	}
}

@script RequireComponent (AudioSource) 

又一个例子:

// A generic stream music player.
//一个普通的流音乐播放器
// Downloads music successively, then starts playing them randomly.
//连续下载音乐,然后随机播放它们
var downloadPath : String[] = ["http://ia301106.us.archive.org/2/items/abird2005-02-10/abird2005-02-10t02.ogg"];
private var downloadedClips : AudioClip[];
private var playedSongs = new Array ();

function Start () {
	downloadedClips = new AudioClip[downloadPath.Length];

	DownloadAll ();

	PlaySongs ();
}

function DownloadAll () {
	for (var i = 0;i < downloadPath.length; i++) {
		var path = downloadPath[i];
		var download = new WWW (path);
		yield download;
		downloadedClips[i] = download.oggVorbis;

		if (downloadedClips[i] == null)
			Debug.Log("Failed audio download " + path);
	}
}

function PickRandomSong () : AudioClip {
	var possibleSongs = Array ();

	// Build a list of all songs that completed their download
	//下载完成,建立一个所有歌曲列表
	for (var i = 0; i < downloadedClips.length; i++) {
		if (downloadedClips[i] != null)
			possibleSongs.Add(i);
	}

	// No songs downloaded yet
	//仍没有歌曲下载
	if (possibleSongs.length == 0)
		return null;

	// We played all songs, pick from any song now
	//我们播放的所有歌曲,从现在挑选任何歌曲
	if (possibleSongs.length == playedSongs.length)
		playedSongs.Clear();

	// Remove songs that were played already from the list of songs
	//从播放列表移除播放完的歌曲
	for (i = 0; i < playedSongs.length; i++)
		possibleSongs.Remove (playedSongs[i]);

	// Pick a random song
	//选择一个随机播放歌曲
	if (possibleSongs.length != 0) {
		var index : int= possibleSongs[Random.Range(0, possibleSongs.length)];
		playedSongs.Add(index);
		return downloadedClips[index];
	}
	else
	return null;
}

function PlaySongs () {
	while (true) {
		var clip : AudioClip = PickRandomSong ();
		if (clip != null) {
			audio.clip = clip;
			audio.Play();
			yield WaitForSeconds(clip.length);
		}
		yield;
	}
}

@script RequireComponent(AudioSource)
Page last updated: 2011-4-25