上篇介绍了手机风波(一)の感触,大家读过之后一定怀疑是我点儿背。嘻嘻,想必大家都听过一句古话:塞翁失马焉知非福!要知如何让我的手机起死回生的,请听我慢慢讲来:
方法1.手机买来没多长时间,是韩学长帮我用他的京东商城的号买的。于是我想让他帮我申请一下返厂维修。可是学长应该是学业为重没时间,于是帮我稍微写了一些返厂理由就提交了,之后给我他的号让我自己看着办。。。果然不出所料,没过多长时间收到短信提醒返厂请求被退回。
方法2.我打算拿到手机店修理,可是在修理之前我想自己捣鼓一下,看看能否修好。拿着手机我静静的回忆手机坏掉的时候有的时候能用一下,有的时候不能用,甚至不能开机。于是就总结了一下能用的时候的共同点:用力拿着手机的时候或者紧握手机的时候它就能正常开机,并且为我所用。
想到这里,我似乎找到了问题的答案,于是我向小刘童鞋借来小改锥把手机的螺丝全部卸掉之后试图打开手机看看是否内部部件有松动的情况导致屏幕与主板之间接触不良。谁知,螺丝卸掉之后手机还是打不开。。。不过在卸载螺丝的时候我发现一个细节:有点螺丝有些许的松动,可能是摔得原因。如果是酱紫的话,按道理我只要把螺丝拧紧之后就可以啦!事实果然如此!!我把螺丝拧紧之后,手机果然复活了!!
我太开心了,以前我总是不敢拆卸电子产品,这件事给了我最大的鼓励。感谢上天让我经历这一切!嘿嘿
1楼lfmilaoshi昨天 21:53重要的是勇于去发现,勇于动手实践。Re: u0108928411小时前回复lfmilaoshin恩恩,我会一点点的去学会自己动手做一些事情的
截图:
其实视频播放器的实现与音乐播放器的实现没有太大的区别。主要体现在:
1)main.xml
增加了<ImageView />(用来显示图片按钮)、<SurfaceView />(用来作为屏幕)
2)MainActivity
其实大部分还是一样的。只是在MP3音乐播放器的基础上早合适的位置上增加了以下:
SurfaceHolder holder = surfaceView.getHolder(); holder.setFixedSize(176, 144);//设置分辨率 holder.setKeepScreenOn(true);//保持屏幕高亮 holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);//不维持缓冲,得到数据后直接输出
mp.setDisplay(surfaceView.getHolder());//设置显示画面
代码如下:
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@android:color/white">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="女神牌mp4视频播放器"
/>
<EditText
android:id="@+id/et_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="oppo.mp4"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/play/index.html"
android:onClick="play"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/pause/index.html"
android:onClick="pause"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/stop/index.html"
android:onClick="stop"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="/blog_article/@drawable/reset/index.html"
android:onClick="reset"
android:layout_marginRight="10dp"
/>
</LinearLayout>
<SurfaceView
android:id="@+id/sv_info"
android:layout_width="fill_parent"
android:layout_height="224dp"
/>
</LinearLayout>
2、MainActivity
package com.NJUPT.mp4_1;
import java.io.File;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private MediaPlayer mp;
private File file;
private EditText et_name;
private boolean pause;
private int position = 0;
private SurfaceView surfaceView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et_name = (EditText) findViewById(R.id.et_name);
surfaceView = (SurfaceView) findViewById(R.id.sv_info);
SurfaceHolder holder = surfaceView.getHolder();
holder.setFixedSize(176, 144);
holder.setKeepScreenOn(true);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
public void play(View v) {
String name = et_name.getText().toString();
file = new File(Environment.getExternalStorageDirectory(), name);
if (!file.exists()) {
Toast.makeText(this, "sorry,视频文件不存在", 1).show();
} else {
play();
}
}
public void play() {
try {
mp = new MediaPlayer();
mp.reset();
mp.setDataSource(file.getAbsolutePath());
mp.setDisplay(surfaceView.getHolder());
mp.prepare();
mp.setOnPreparedListener(new MyOnPrepareListener());
} catch (Exception e) {
e.printStackTrace();
}
}
private class MyOnPrepareListener implements OnPreparedListener {
@Override
public void onPrepared(MediaPlayer mp) {
mp.start();
}
}
public void pause(View v) {
if (mp != null) {
if (mp.isPlaying()) {
mp.pause();
pause = true;
} else {
mp.start();
pause = false;
}
}
}
public void stop(View v) {
if (mp != null) {
mp.stop();
}
}
public void reset(View v) {
stop(v);
play();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
源代码下载地址为:
http://download.csdn.net/detail/caihongshijie6/6285127
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<SurfaceView
android:id="@+id/surfaceview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="对焦"
android:onClick="focus"
android:layout_marginRight="10dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="拍照"
android:onClick="takepicture"
android:layout_marginRight="10dp"
/>
</LinearLayout>
</RelativeLayout>
2、MainActivity
package com.njupt.takepicture1;
import java.io.File;
import java.io.FileOutputStream;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.hardware.Camera.PictureCallback;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.view.SurfaceHolder;
import android.view.SurfaceHolder.Callback;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends Activity {
private SurfaceView surfaceview;
private Camera camera;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
surfaceview = (SurfaceView) findViewById(R.id.surfaceview);
SurfaceHolder holder = surfaceview.getHolder();
holder.setFixedSize(176, 144);
holder.setKeepScreenOn(true);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(new MySurfaceCallback());
}
private class MySurfaceCallback implements Callback {
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
// TODO Auto-generated method stub
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = Camera.open();
Parameters params = camera.getParameters();
params.setJpegQuality(90);
params.setPictureSize(1024, 768);
params.setPreviewFrameRate(10);
camera.setParameters(params);
camera.setPreviewDisplay(surfaceview.getHolder());
camera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (camera != null) {
camera.release();
camera = null;
}
}
}
public void takepicture(View v) {
camera.takePicture(null, null, new MyPictureCallback());
}
private class MyPictureCallback implements PictureCallback {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
try {
File file = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
camera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
3、AndroidManifest.xml
注册权限
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
横屏显示:
<activity
android:name="com.njupt.takepicture1.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape">