code.club

標題: Processing如何在android上放聲音/Play sound in Android for Processing [打印本頁]

作者: processor    時間: 2017-2-21 16:33
標題: Processing如何在android上放聲音/Play sound in Android for Processing
本帖最後由 processor 於 2017-2-21 16:45 編輯

目前(2017/02/21)有二種 library 可以讓 Processing 寫的程式在 android 手機上播放聲音,分別是 apwidgets 和 cassette 。
cassette的下載點在 https://github.com/shlomihod/cassette 以及 apwidgets的下載點  https://github.com/barefists/APmediaPlayer
如果年久失修,就自己上網搜尋一下 processing android audio cassette 或者 apwidgets 看看,愈新愈好。但我們自己的 Processing 版本也要考慮,隨著版本不斷更新,未必都能很 match 的,尤其是 Processing 裡面的 Android mode,也要適時更新,太舊的版本也未必能適用新的 library 。

下載上述任何一種 library 之後,就將它們解壓縮並且放在Processing Sketchbook 中的 libraries 中,如果它們解壓縮之後預設的目錄名稱不是apwidgets 和 cassette,記得請將它們的目錄名稱分別改成 apwidgets 和 cassette,反正一定要符合它目錄裡面 library裡面的那個 .jar 檔的名稱。然後重新啟動 Processing ,應該會在 Sketch->import Library裡看到多出上述的新library名稱。

Play sound in Android mode for Processing:
There are 2 libraries that both can work for now(2017/02/21), also remember to update your android mode if things not working. You can try any one of them to see if it works in your situation.
To download cassette library  at https://github.com/shlomihod/cassette .
To download apwidgets library at https://github.com/barefists/APmediaPlayer .
Unzip those files and remember to change their directory name to cassette/apwodgets and put them in your Sketchbook libraries.
Then reopen Processing you should see them now in your Sketch->import Library .
If you find this article in many years later then this article written, chances are these 2 libraries are not working for your new Processing or Android mode, or the download links are not available, so you should try to find if there are any newer versions.


cassette的語法大致如下:
Example for cassette:

import cassette.audiofiles.SoundFile;

SoundFile player;

void setup() {
    background(255, 0, 0);

    player = new SoundFile(this, "test.wav"); /*這個要放在自己設的 data 目錄裡面。Remember to place sound file at directory named data, if there is no data directory in your project directory then you should make one. */
       
    player.loop();
}

void draw() {
}

void mousePressed() {
    player.stop();
}

apwidgets的語法大致如下:
Example for cassette:

import apwidgets.*;
APMediaPlayer player;

void setup(){
  player = new APMediaPlayer(this);
  player.setMediaFile("test.mp3");
  player.start();
}

void draw(){
  background(255,255,0);
  
}

void mousePressed(){
  player.pause();
  player.release();
}

作者: processor    時間: 2017-2-23 23:40
Some related discussion threads:

https://forum.processing.org/two/search?Search=cassette





歡迎光臨 code.club (https://code.club/) Powered by Discuz! X3.2