2013年2月28日木曜日

YOUR PHONE MAY NOT BE PROVISIONED FOR DATA SERVICES

アカウントのセットアップ時にYOUR PHONE MAY NOT BE PROVISIONED FOR DATA SERVICESというエラーが出た。

原因は日付・時刻が正しく無かったためであった。
( しばらく起動してなかったので時刻は1970/1/1 09:00に・・・ )

これを現在時刻に直してから試したら成功した。


2013年1月29日火曜日

(iOS) UISlider::setValueでsliderが再描画されない。

UISlider::setValueはUIスレッドから呼び出さないと再描画処理が行われません。
別スレッドから読んでいる場合はUIスレッドから呼ぶようにしましょう。

[self performSelectorOnMainThread:@selector(updateSlider) withObject:nil waitUntilDone:NO];

ExtAudioFileSeek→ExtAudioFileReadでError -50

iOSで音楽の読み込みを行うAPIにExtAudioFileRead( fileReference , size,  buffer )がある。

また、シークするAPIとしてExtAudioFileSeek( fileReference, seekTo )がある。

ExtAudioFileSeekを呼び出すことで読み出し位置を変更できるのだが、ファイルを最後まで読みだした後にExtAudioFileSeekで適当な位置にシークし、再びExtAudioFileReadで読みだしても、error -50が返され読み出しに失敗する。(読み出しバイト数は0となっている。)

全然原因がわからなくて調べていたら全く同じ内容で困ってる人がいた

なんと、バッファのサイズを示すbuffer->mBuffers[i].mDataByteSizeが、ExtAudioFileReadで読み出されたデータのバイト数で上書きされてしまうとのこと。

なので、ファイル終端まで再生すると、ファイル終端では読み出されるデータのバイト数が0になるため、buffer->mBuffers[i].mDataByteSizeも0になってしまう。

で、その後シークして読み出そうとしても、サイズ0のバッファをExtAudioFileReadに渡した事になり、データの読みだしが1byteも行われないのである。

というわけで、解決策はExtAudioFileReadを実行したら必ずbuffer->mBuffers[i].mDataByteSizeを実際に確保しているバッファサイズで上書きすること。

ExtAudioFileRead(fileReference, &size, buffer);
for(UInt32 i=0 ; isourceBuffer->mNumberBuffers ; i++){
   buffer->mBuffers[i].mDataByteSize = BUFF_SIZE;
}

ExtAudioFileReadの2つ目の引数sizeが、読みだすサイズの指定をしながら、実際に読み出されたbyte数で上書きされる、っていう仕様はまぁよくある話だけど、さらに他の引数で与えた構造体のメンバも同じデータで上書きするってのはちょっと仕様としてどうなの?これはExtAudioFileReadのリファレンスに何か書いてくれなきゃわかんないよう。

2012年11月24日土曜日

テーマHoloを利用しつつメニューボタンを表示する

ICS以降はActionbarが推奨され、消えてしまったメニューボタンですが、
救済策として、メニューキーのない端末では画面の右下にメニューボタンが表示されます。

しかし、target-sdkが14以上の場合、これらのボタンは表示されず、
requestWindowFeature(Window.FEATURE_NO_TITLE);のようにしてタイトルバー(アクションバー)を消している場合、オプションメニューにアクセスできなくなってしまいます。

target-sdkが13以下の時はメニューが表示されるようです。
どうしても従来のメニューボタンを表示させておきたい場合は、target-sdkを13以下にしておきましょう。

なお、target-sdkが11以上( Honeycomb以降 )の場合、デフォルトのテーマはHoloになります。

なので、テーマがHoloでメニューボタンを表示させたい場合、target-sdkは11-13を選択すれば良いことになります。

※target-sdkを11-13にしても、tabletの場合はレガシーメニューボタンが表示されません。こればっかりは仕方ありません。タブレット場合はActionBarを表示するようにしましょう。端末がタブレットか否かを調べる方法は以下のリンクに書いてあります。
http://stackoverflow.com/questions/5832368/tablet-or-phone-android

2012年11月23日金曜日

PreferenceActivity and Intent

The information about PreferenceActivity is here.

We can use intents in PreferenceActivity.
Here is some examples of usage of <intent> in PreferenceActivity.

<PreferenceScreen android:title="Show in market." >
<intent
    android:action="android.intent.action.VIEW"
    android:data="market://details?id=jp.ne.sakura.ccice.audipo" />
</PreferenceScreen>
<PreferenceScreen android:title="Send an mail to developer." >
    <intent
        android:action="android.intent.action.VIEW"
        android:data="mailto:hogehoge@foo.com" />
</PreferenceScreen>
<PreferenceScreen android:title="Share this app." >
    <intent
        android:action="android.intent.action.SEND"
        android:mimeType="text/plain" >
        <extra
            android:name="android.intent.extra.TEXT"
            android:value="Texts to share." />
    </intent>
</PreferenceScreen>

2012年11月14日水曜日

Solve "Signature Verification Failed" error

I met Signature Verification Failed error  in CWM. when I updated my Galaxy Nexus(yakju) ( OTA  , JRO03C to JZO54K )

I remembered My Galaxy Nexus was rooted by Nexus Root Toolkit(NRT) 1.5.2.
I tried to root Galaxy Nexus again with Nexus Root Toolkit 1.5.5 ( newest version ).
And flash OTA again.
Now, CWM didn't say any error.

I use NRT again to root the device this time!

2012年11月8日木曜日

RemoteControleClientを使うにはAudioFocusが必要

RemoteControlClientはテクブに書いてある通りに書けば動きま・・・せん。

リモートコントロールを表示するにはAudioFocusを取得する必要があります。
省略されているのは、それくらい常識って事なんでしょうか。

     ComponentName myEventReceiver = new ComponentName(getPackageName(), MusicIntentReciever.class.getName());
     AudioManager myAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
     myAudioManager.registerMediaButtonEventReceiver(myEventReceiver);
     myAudioManager.requestAudioFocus( new OnAudioFocusChangeListener() {
          @Override
          public void onAudioFocusChange(int focusChange) {
                Log.d(TAG, "focusChanged:"+focusChange );
          }
     } , AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
     
     // build the PendingIntent for the remote control client
     Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
     mediaButtonIntent.setComponent(myEventReceiver);
     PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(this, 0, mediaButtonIntent, 0);
     
     // create and register the remote control client
     mRemoteControlClient = new RemoteControlClient(mediaPendingIntent);
     myAudioManager.registerRemoteControlClient(mRemoteControlClient);
     mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
     mRemoteControlClient.setTransportControlFlags(
                  RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
                  RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
                  RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
                  RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
                  RemoteControlClient.FLAG_KEY_MEDIA_STOP);
     mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
     mRemoteControlClient.editMetadata(true)
           .putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, "a")
           .putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, "b")
           .putString(MediaMetadataRetriever.METADATA_KEY_TITLE, "c")
           .apply();

MusicIntentRecieverはAndroid SDKのサンプルのRandomMusicPlayerに含まれているものが使えます。そちらを参考にして下さい。