zoukankan      html  css  js  c++  java
  • mediaplayer与surfaceView,无法播放问题

     mediaplayer需要在surfaceView创建之后才能创建,不然会导致错误。

    1 surfaceholder = msurface.getHolder();
    2         surfaceholder.setKeepScreenOn(true);
    3         surfaceholder.addCallback(new SurfaceViewLis());
     1 private class SurfaceViewLis implements SurfaceHolder.Callback {  
     2           
     3         @Override  
     4         public void surfaceChanged(SurfaceHolder holder, int format, int width,  
     5                 int height) {  
     6   
     7         }  
     8   
     9         @Override  
    10         public void surfaceCreated(SurfaceHolder holder) {  
    11             mPlayer = MediaPlayer.create(AnimationGuideActivity.this, R.raw.guideanimation);
    12             mPlayer.setDisplay(holder);
    13             mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
    14                 
    15                 @Override
    16                 public void onCompletion(MediaPlayer arg0) {
    17                     // TODO Auto-generated method stub
    18                     Intent intent = new Intent(AnimationGuideActivity.this, IrisActivity.class);
    19                     finish();
    20                     startActivity(intent);
    21                 }
    22             });
    23 
    24             try {
    25                 mPlayer.setOnPreparedListener(new OnPreparedListener() {
    26                     
    27                     @Override
    28                     public void onPrepared(MediaPlayer arg0) {
    29                         mPlayer.start();
    30                         
    31                     }
    32                 });
    33                 mPlayer.prepareAsync();
    34             } catch (IllegalStateException  e) {
    35                 // TODO Auto-generated catch block
    36                 e.printStackTrace();
    37             }
    38   
    39         }  
    40   
    41         @Override  
    42         public void surfaceDestroyed(SurfaceHolder holder) {  
    43   
    44         }  
    45   
    46     }  
  • 相关阅读:
    Visual Studio color schemes
    WebForm服务器验证控件与前端js自定义验证共同使用
    Powerdesigner设计表生成SQL脚本(带有注释)
    JS日期格式化
    C# 生成小于Int数值绝对值的随机数
    LINQ解析
    Could not calculate build plan:
    Maven Tomcat webapp
    用JS来改变CSS样式
    安装 groovy eclipse 插件
  • 原文地址:https://www.cnblogs.com/zl1991/p/5283420.html
Copyright © 2011-2022 走看看