首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Videoplayer无法在开机画面中播放视频

Videoplayer无法在开机画面中播放视频
EN

Stack Overflow用户
提问于 2013-04-19 20:12:16
回答 1查看 85关注 0票数 0

我在我的应用程序中有一个splahs屏幕,我正在播放该活动的视频。但在一些Android版本(我指的是老版本)中,视频不能播放。我不知道该怎么办..

下面是我的一些代码

代码语言:javascript
复制
 public void PlayVideo(){
    try{             
            videoPlayer.setDataSource(getApplicationContext(), Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.afad_splash_ip4));
            videoPlayer.prepare();
        }
        catch (Exception e){

        }
    try {
          AssetFileDescriptor descriptor = getAssets().openFd("splash.mp4");             
          videoPlayer.reset();           
          videoPlayer.setDataSource(descriptor.getFileDescriptor());              
          videoPlayer.prepare();          
          }
          catch (Exception ex)
            {
              try
              {                   
               Log.v("video ", "catch");
               videoPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
               videoPlayer.setVolume(0f, 0f);
               videoPlayer.start();
               videoPlayer.setLooping(false);                   
               videoPlayer.setOnCompletionListener(new OnCompletionListener() {
                public  void onCompletion(MediaPlayer mp) {
                    Intent i = new Intent(VideoSplash.this,ListActivity.class);
                    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                    overridePendingTransition(R.anim.slide_in_top,R.anim.slide_out_bottom);
                    finish();
                    }
                });
              }
              catch (Exception e)
                 {      //TODO
                     //Burada Video yerine resim koymalısın
                     //Kimi cihazlarda video oynamayabilir
                  Log.v("resim", "catch");
                  //Thats where i want to put a pic as a backgroun to my SurfaceView. and make it wait 10 secs
                 // videoSurface.setBackgroundDrawable(getResources().getDrawable(R.drawable.son_frame));
                  }
                //TODO
            //Burada Video yerine resim koymalısın
            //Kimi cihazlarda video oynamayabilir               

            }                      


    }
EN

回答 1

Stack Overflow用户

发布于 2013-04-19 20:35:33

试试这段代码会对你有帮助。

代码语言:javascript
复制
public class VideoPlayerActivity extends Activity implements OnErrorListener,
OnPreparedListener {

LoadAsyncTask video_async_task;

private VideoView  mVideoView

public void onCreate(Bundle icicle) {

super.onCreate(icicle); 
setContentView(R.layout.video);
mVideoView = (VideoView) findViewById(R.id.mysurfaceview);
mVideoView.setMediaController(myctrl);


mVideoView.requestFocus();

video_async_task = new LoadAsyncTask();
video_async_task.execute();

}

private class LoadAsyncTask extends AsyncTask<Void, Void, Void> {

protected Void doInBackground(Void... params) { 

mVideoView.setVideoURI(Uri.parse(path));

}


}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16104348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档