Break mobile phone into nursery rhyme player

I found a mobile phone whose touch screen could not be touched, but displayed no problem, and wrote a small program to play nursery rhymes to my baby.

Computer control mobile phone software

Full Control http://tc.sigma-rt.com.cn/

Set the app to start on startup

The manifest.xml file is set as follows:

   <activity
        android:name=".FullscreenActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category        android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

horizontal screen

Modify the onResume method of Activity according to the following code example

@Override
protected void onResume() {
 /**
  * 设置为横屏
  */
     if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
 }
 super.onResume();
}

Or add to the Activity node in the configuration file

android:screenOrientation属性(landscape是横向,   portrait是纵向)
android:launchMode="singleTask"  
  android:screenOrientation="portrait">

screen constant

view.setKeepScreenOn(true)

Intercept the system volume keys

// 拦截系统热键
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
int key = event.getKeyCode();
        Log.i(TAG, "[test] dispatchKeyEvent  event = " + event);
    if (key == KeyEvent.KEYCODE_VOLUME_DOWN
        || key == KeyEvent.KEYCODE_VOLUME_UP) {
        Log.i(TAG, "[test] catch  event!! return true! ");
        return true;
    }
    return super.dispatchKeyEvent(event);
}

Respond only to key ups

 if ( event.getAction()  == KeyEvent.ACTION_DOWN) {

               return true;// only response to key up
           }

file/folder traversal

File f = new File(Environment.getExternalStorageDirectory().getPath()+"/videohome/");
    File[] temp_dirs = f.listFiles();
    int count = 0;
    for(File dir : temp_dirs) {
        if (dir.isDirectory()) {
            count++;
        }
    }
    dirs = new File[count];

    for(File dir : temp_dirs) {
        if (dir.isDirectory()) {
            Log.e("haha",dir.toString());
            dirs[--count] = dir;
        }
    }

generate random numbers

(new Random()).nextInt( files.length);

video playback

this.videoView = (VideoView)this.findViewById(R.id.videoView);
    //videoView.setMediaController(new    MediaController(this));
        final MediaController mc = new MediaController(this);
    mc.setVisibility(View.INVISIBLE);
    mc.setEnabled(false);


    videoView.setMediaController(mc);

     videoView.setVideoURI(Uri.parse(file.toURI().toString()));
    videoView.start();
    videoView.requestFocus();

 videoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            播放下一首
        }
 }

videoview video stretch full screen

 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentBottom="true"

layout changed to RelativeLayout

{{o.name}}
{{m.name}}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324195737&siteId=291194637