Processing Osc 文字化け
PythonでTwitter APIからデータ取得したのにProcessing にOSC通信したら文字化けしたので,解消したかったが思いのほか記事が少なかった.
http://mirror.boy.jp/?p=809
参考にしたのはここ↑
import oscP5.*; import netP5.*; import java.io.UnsupportedEncodingException; //ここ初めて使った.知らなかった. OscP5 oscP5; NetAddress myRemoteLocation; int receivePort = ????; String sendIP = "????"; String tweet = ""; void setup(){ size(1000, 1000); background(255); oscP5 = new OscP5(this,receivePort); myRemoteLocation = new NetAddress(sendIP,sendPort); } void draw(){ background(255); fill(0); text(tweet, 0, 50); } void oscEvent(OscMessage theOscMessage) { print("### received an osc message."); println(" addrpattern: "+theOscMessage.addrPattern()); if(theOscMessage.checkAddrPattern("/tweet")==true) { byte[] bytes = theOscMessage.getBytes(); try { tweet = new String(bytes, "UTF-8"); String typeTagStr = theOscMessage.typetag(); tweet = tweet.substring(tweet.indexOf(typeTagStr) + typeTagStr.length()); println("Tweet:"+tweet); } catch(UnsupportedEncodingException e) { e.printStackTrace(); } } }