我是Android新手,这是我第一次尝试使用VideoView。我正在流式传输几个MP4文件,第一个(大约5mb和1分钟)自动打开另外两个(大约100mb和1小时)需要用户交互,当它运行正常时,堆不断增长,最终它开始产生内存错误并且在用户交互时将强制关闭。我知道我错过了一些东西并犯了一些错误,但希望有人能够帮助我解决这些问题,并可能教育我什么和为什么。谢谢你的时间。
public class VideoPlayer extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
Uri video = Uri.parse("URL");
videoView.setVideoURI(video);
videoView.requestFocus();
videoView.start();
View Button1 = findViewById(R.id.video1);
Button1.setOnClickListener(this);
View Button2 = findViewById(R.id.video2);
Button2.setOnClickListener(this);
}
public void onClick(View view) {
VideoView videoView = (VideoView) findViewById(R.id.VideoView);
switch (view.getId()) {
case R.id.video1:
Uri video1 = Uri.parse("URL");
videoView.setVideoURI(video1);
videoView.requestFocus();
videoView.start();
Toast.makeText(VideoPlayer.this, "Episode1", Toast.LENGTH_SHORT).show();
break;
case R.id.video2:
Uri video2 = Uri.parse("URL");
videoView.setVideoURI(video2);
videoView.requestFocus();
videoView.start();
Toast.makeText(VideoPlayer.this, "Episode 2", Toast.LENGTH_SHORT).show();
break;
}
}
}
Log Cat:
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at com.admob.android.ads.u.a(AssetDownloader.java:211)
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at com.admob.android.ads.i.d(AdMobURLConnector.java:201)
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at com.admob.android.ads.i.run(AdMobURLConnector.java:284)
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
02-12 01:36:18.407 21977 25284 E AdMobSDK:
at java.lang.Thread.run(Thread.java:1058)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
couldn't create a Bitmap
02-12 01:36:18.507 21977 25285 E AdMobSDK:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:308)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:321)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at com.admob.android.ads.u.a(AssetDownloader.java:211)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at com.admob.android.ads.i.d(AdMobURLConnector.java:201)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at com.admob.android.ads.i.run(AdMobURLConnector.java:284)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
02-12 01:36:18.507 21977 25285 E AdMobSDK:
at java.lang.Thread.run(Thread.java:1058)
02-12 01:36:18.507 21977 25285 E AndroidRuntime:
Crash logging skipped, alreadylogging another crash
02-12 01:36:18.517 21977 25285 I AdMobSDK:
assetsDidFailToLoad()
02-12 01:36:18.527 21977 25284 I AdMobSDK:
assetsDidFailToLoad()
02-12 01:36:38.587 21977 25296 I AdMobSDK:
No fill. Server replied that no ads are available (859ms)
02-12 01:37:00.887 21977 25285 E dalvikvm-heap:
14400-byte external allocation too large for this process.
02-12 01:37:00.907 21977 25285 E :
VM won't let us allocate 14400 bytes
02-12 01:37:01.017 21977 25284 E dalvikvm-heap:
1444-byte external allocation to o large for this process.
02-12 01:37:01.017 21977 25284 E :
VM won't let us allocate 1444 bytes
02-12 01:37:01.057 21977 25285 E AdMobSDK:
couldn't create a Bitmap
02-12 01:37:01.057 21977 25285 E AdMobSDK:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:308)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:321)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at com.admob.android.ads.u.a(AssetDownloader.java:211)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at com.admob.android.ads.i.d(AdMobURLConnector.java:201)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at com.admob.android.ads.i.run(AdMobURLConnector.java:284)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
02-12 01:37:01.057 21977 25285 E AdMobSDK:
at java.lang.Thread.run(Thread.java:1058)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
couldn't create a Bitmap
02-12 01:37:01.137 21977 25284 E AdMobSDK:
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at android.graphics.BitmapFactory.nativeDecodeByteArray(Native Method)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:308)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at android.graphics.BitmapFactory.decodeByteArray(BitmapFactory.java:321)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at com.admob.android.ads.u.a(AssetDownloader.java:211)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at com.admob.android.ads.i.d(AdMobURLConnector.java:201)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at com.admob.android.ads.i.run(AdMobURLConnector.java:284)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:648)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:673)
02-12 01:37:01.137 21977 25284 E AdMobSDK:
at java.lang.Thread.run(Thread.java:1058)
02-12 01:37:01.157 21977 25284 E AndroidRuntime:
Crash logging skipped, alreadylogging another crash
02-12 01:37:01.177 21977 25284 I AdMobSDK:
assetsDidFailToLoad()
02-12 01:37:21.367 21977 25317 I AdMobSDK:
No fill. Server replied that no adsare available (914ms)
02-12 01:37:42.327 21977 25326 I AdMobSDK:
No fill. Server replied that no ads are available (902ms)
02-12 01:38:00.027 21977 21977 E dalvikvm-heap:
1024-byte external allocation to o large for this process.
02-12 01:38:00.047 21977 21977 E :
VM won't let us allocate 1024 bytes
02-12 01:38:06.747 94 117 W WindowManager:
Key dispatching timed out sending to com.test.player.one/com.test.player.one.VideoPlayer
02-12 01:38:06.757 94 117 W WindowManager:
Dispatch state: {{KeyEvent{action=1 code=25 repeat=0 meta=0 scancode=53 mFlags=8} to Window{4372b048 Panel:com.test.player.one/com.test.player.one.VideoPlayer paused=false} @ 1297496735963 lw=Window{4372b048 Panel:com.test.player.one/com.test.player.one.VideoPlaye
r paused=false} lb=android.os.BinderProxy@43708e60 fin=false gfw=true ed=true tt
s=0 wf=false fp=false mcf=Window{437e9590 Panel:com.test.player.one/com.test
.player.one.VideoPlayer paused=false}}}
02-12 01:38:06.767 94 117 W WindowManager:
Current state: {{null to Window{4351cc20com.test.player.one/com.test.player.one.VideoPlayer paused=false}
@ 1297503486770 lw=Window{4351cc20 com.test.player.one/com.test.player.one.V
ideoPlayer paused=false} lb=android.os.BinderProxy@435f0470 fin=false gfw=true e
d=true tts=0 wf=false fp=false mcf=Window{437e9590 Panel:com.test.player.one/c
om.test.player.one.VideoPlayer paused=false}}}
02-12 01:38:11.777 94 117 W WindowManager:
Key dispatching timed out sending to com.test.player.one/com.test.player.one.VideoPlayer
02-12 01:38:11.787 94 117 W WindowManager:
Dispatch state: {{KeyEvent{action=1 code=25 repeat=0 meta=0 scancode=53 mFlags=8} to Window{4372b048 Panel:com.test.player.one/com.test.player.one.VideoPlayer paused=false} @ 1297496735963 lw=Window{4372b048 Panel:com.test.player.one/com.test.player.one.VideoPlaye
r paused=false} lb=android.os.BinderProxy@43708e60 fin=false gfw=true ed=true tt
s=0 wf=false fp=false mcf=Window{437e9590 Panel:com.test.player.one/com.test
.player.one.VideoPlayer paused=false}}}
02-12 01:38:11.787 94 117 W WindowManager:
Current state: {{null to Window{4351cc20 com.test.player.one/com.test.player.one.VideoPlayer paused=false}
@ 1297503491791 lw=Window{4351cc20 com.test.player.one/com.test.player.one.V
ideoPlayer paused=false} lb=android.os.BinderProxy@435f0470 fin=false gfw=true e
d=true tts=0 wf=false fp=false mcf=Window{437e9590 Panel:com.test.player.one/c
om.test.player.one.VideoPlayer paused=false}}}
02-12 01:38:11.887 94 117 I ActivityManager:
ANR (application not responding) in process: com.test.player.one
02-12 01:38:11.887 94 117 I ActivityManager:
Annotation: keyDispatchingTimedOut
02-12 01:38:11.887 94 117 I ActivityManager: CPU usage:
02-12 01:38:11.887 94 117 I ActivityManager: Load: 4.27 / 4.6 / 4.88
02-12 01:38:11.887 94 117 I ActivityManager: CPU usage from 11872ms to 78ms
ago:
02-12 01:38:11.887 94 117 I ActivityManager: system_server: 4% = 3% user
+ 1% kernel
02-12 01:38:11.887 94 117 I ActivityManager: adbd: 1% = 0% user + 0% kern
el
02-12 01:38:11.887 94 117 I ActivityManager: events/0: 0% = 0% user + 0%
kernel
02-12 01:38:11.887 94 117 I ActivityManager: com.test.player.one: 0% =
0% user + 0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: wpa_supplicant: 0% = 0% user
+ 0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: com.android.inputmethod.lati
n: 0% = 0% user + 0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: krpcserversd: 0% = 0% user +
0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: kondemand/0: 0% = 0% user +
0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: servicemanager: 0% = 0% user
+ 0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: port_bridge: 0% = 0% user +
0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: dhd_dpc: 0% = 0% user + 0% k
ernel
02-12 01:38:11.887 94 117 I ActivityManager: com.motorola.atcommand: 0% =
0% user + 0% kernel
02-12 01:38:11.887 94 117 I ActivityManager: logcat: 0% = 0% user + 0% ke
rnel
02-12 01:38:11.887 94 117 I ActivityManager: TOTAL: 9% = 5% user + 3% kerne
l
02-12 01:38:11.897 94 117 I ActivityManager: Removing old ANR trace file fr
om /data/anr/traces.txt
02-12 01:38:12.197 94 117 W WindowManager: No window to dispatch pointer ac
tion 1
02-12 01:38:12.337 94 104 E ANRInfo :
ANR information:PID:21977/test VideoPlayer / test VideoPlayer
02-12 01:38:12.337 94 104 E ANRInfo :
Package Name:com.test.player.one
02-12 01:38:12.337 94 104 E ANRInfo :
shortMsg: ANR keyDispatchingTimedOut
02-12 01:38:12.337 94 104 E ANRInfo :
longMsg:
02-12 01:38:12.337 94 104 E ANRInfo :
ANR (application not responding) in process: com.test.player.one
02-12 01:38:12.337 94 104 E ANRInfo :
Annotation: keyDispatchingTimedOut
02-12 01:38:12.337 94 104 E ANRInfo : CPU usage:
02-12 01:38:12.337 94 104 E ANRInfo : Load: 4.27 / 4.6 / 4.88
02-12 01:38:12.337 94 104 E ANRInfo : CPU usage from 11872ms to 78ms ago:
02-12 01:38:12.337 94 104 E ANRInfo : system_server: 4% = 3% user + 1% ke
rnel
02-12 01:38:12.337 94 104 E ANRInfo : adbd: 1% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : events/0: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : com.test.player.one: 0% = 0% user
+ 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : wpa_supplicant: 0% = 0% user + 0% k
ernel
02-12 01:38:12.337 94 104 E ANRInfo : com.android.inputmethod.latin: 0% =
0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : krpcserversd: 0% = 0% user + 0% ker
nel
02-12 01:38:12.337 94 104 E ANRInfo : kondemand/0: 0% = 0% user + 0% kern
el
02-12 01:38:12.337 94 104 E ANRInfo : servicemanager: 0% = 0% user + 0% k
ernel
02-12 01:38:12.337 94 104 E ANRInfo : port_bridge: 0% = 0% user + 0% kern
el
02-12 01:38:12.337 94 104 E ANRInfo : dhd_dpc: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : com.motorola.atcommand: 0% = 0% use
r + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : logcat: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : TOTAL: 9% = 5% user + 3% kernel
02-12 01:38:12.337 94 104 E ANRInfo :
02-12 01:38:12.337 94 104 E ANRInfo :
02-12 01:38:12.337 94 104 E ANRInfo :
com.android.server.am.ActivityManager
Service$AutomaticANRException: ANR information:PID:21977/test VideoPlayer /
test VideoPlayer
02-12 01:38:12.337 94 104 E ANRInfo :
Package Name:com.test.player.one
02-12 01:38:12.337 94 104 E ANRInfo :
shortMsg: ANR keyDispatchingTimedOut
02-12 01:38:12.337 94 104 E ANRInfo :
longMsg:
02-12 01:38:12.337 94 104 E ANRInfo :
ANR (application not responding) in process: com.test.player.one
02-12 01:38:12.337 94 104 E ANRInfo :
Annotation: keyDispatchingTimedOut
02-12 01:38:12.337 94 104 E ANRInfo : CPU usage:
02-12 01:38:12.337 94 104 E ANRInfo : Load: 4.27 / 4.6 / 4.88
02-12 01:38:12.337 94 104 E ANRInfo : CPU usage from 11872ms to 78ms ago:
02-12 01:38:12.337 94 104 E ANRInfo : system_server: 4% = 3% user + 1% ke
rnel
02-12 01:38:12.337 94 104 E ANRInfo : adbd: 1% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : events/0: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : com.test.player.one: 0% = 0% user
+ 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : wpa_supplicant: 0% = 0% user + 0% k
ernel
02-12 01:38:12.337 94 104 E ANRInfo : com.android.inputmethod.latin: 0% =
0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : krpcserversd: 0% = 0% user + 0% ker
nel
02-12 01:38:12.337 94 104 E ANRInfo : kondemand/0: 0% = 0% user + 0% kern
el
02-12 01:38:12.337 94 104 E ANRInfo : servicemanager: 0% = 0% user + 0% k
ernel
02-12 01:38:12.337 94 104 E ANRInfo : port_bridge: 0% = 0% user + 0% kern
el
02-12 01:38:12.337 94 104 E ANRInfo : dhd_dpc: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : com.motorola.atcommand: 0% = 0% use
r + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : logcat: 0% = 0% user + 0% kernel
02-12 01:38:12.337 94 104 E ANRInfo : TOTAL: 9% = 5% user + 3% kernel
02-12 01:38:12.337 94 104 E ANRInfo :
02-12 01:38:12.337 94 104 E ANRInfo :
02-12 01:38:12.337 94 104 E ANRInfo :
at com.android.server.am.ActivityManagerService$2.handleMessage(ActivityManagerService.java:943)
02-12 01:38:12.337 94 104 E ANRInfo :
at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 01:38:12.337 94 104 E ANRInfo :
at android.os.Looper.loop(Looper.java:123)
02-12 01:38:12.337 94 104 E ANRInfo :
at com.android.server.am.ActivityManagerService$AThread.run(ActivityManagerService.java:1293)
02-12 01:38:12.607 94 25339 I DumpStateReceiver:
Finished: 3057 bytes read; status 0
02-12 01:38:12.647 94 25339 I DumpStateReceiver:
Added state dump to 1 crashes
02-12 01:38:58.937 154 360 I TLSStateManager:
org.apache.harmony.nio.internal.SocketChannelImpl@433fecb0: Wrote out 29 bytes of data with 0 bytes remaining.
02-12 02:24:05.567 94 104 I ActivityManager:
Killing process com.test.player.one (pid=21977) at user's request
02-12 02:24:05.617 94 98 I ActivityManager:
Process com.test.player.one (pid 21977) has died.
02-12 02:24:05.627 94 3990 I WindowManager:
WIN DEATH: Window{4351cc20 com.test.player.one/com.test.player.one.VideoPlayer paused=false}
02-12 02:24:05.647 94 4769 I WindowManager:
WIN DEATH: Window{435200f0 SurfaceView paused=false}
02-12 02:24:05.647 94 249 I WindowManager:
WIN DEATH: Window{437e9590 Panel:com.test.player.one/com.test.player.one.VideoPlayer paused=false}
02-12 02:24:05.697 94 98 I PowerManagerService:
keypad run :false:0:0
02-12 02:24:05.697 54 23705 E QCvdec : =====================================
=================================
02-12 02:24:05.707 54 23705 E QCvdec : Open Max Statistic
s
02-12 02:24:05.707 54 23705 E QCvdec : =====================================
=================================
02-12 02:24:05.707 54 23705 E QCvdec : empty this buffer rate = 23.981506
02-12 02:24:05.707 54 23705 E QCvdec : empty this buffer total time = 328444
7535
02-12 02:24:05.707 54 23705 E QCvdec : empty this buffer count = 78766
02-12 02:24:05.717 54 23705 E QCvdec : =====================================
=================================
02-12 02:24:05.717 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.717 54 23705 E QCvdec : Arm Statistics
02-12 02:24:05.717 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.717 54 23705 E QCvdec : Total number of frames decoded = 7876
2
02-12 02:24:05.717 54 23705 E QCvdec : Average Arm time/frame(ms) = 0.75
7315
02-12 02:24:05.727 54 23705 E QCvdec : Frames Arm Decoded/sec = 1320
.454102
02-12 02:24:05.727 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.727 54 23705 E QCvdec : Frame Done Statis
tics
02-12 02:24:05.727 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.727 54 23705 E QCvdec : frame done cumulative time = 1772
355679
02-12 02:24:05.727 54 23705 E QCvdec : Frames Done per second = 44.4
38599
02-12 02:24:05.727 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.727 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.727 54 23705 E QCvdec : Dsp Statistics
02-12 02:24:05.727 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.727 54 23705 E QCvdec : Total number of frames decoded = 7876
2
02-12 02:24:05.727 54 23705 E QCvdec : Average Dsp time/frame(ms) = 16.7
85728
02-12 02:24:05.727 54 23705 E QCvdec : Frames Dsp Decoded/sec) = 59.5
74417
02-12 02:24:05.737 54 23705 E QCvdec : =====================================
======================
02-12 02:24:05.767 94 113 I PowerManagerService:
keypad run :false:0:0
02-12 02:24:05.787 54 89 W AudioFlinger:
write blocked for 195 msecs
02-12 02:24:05.887 94 11446 W InputManagerService:
Got RemoteException sending setActive(false) notification to pid 21977 uid 10049