2016-07-31 4 views
0

似たような質問も答えも見つからなかったので、新しいものを投稿することにしました。WindowManagerを使用してグローバルレイアウトに追加したときにVideoViewがビデオを再生しない

カスタマイズされたRelativeLayoutを作成しました。これは、コンテンツレイアウトのラッパーとして機能し、いわゆるラッパーの初期化時にラッパーに追加されて追加されます。

ビデオ再生を除いてすべてが正常であるようですが、実際にはビデオは全くロードされません(onPreparedは決して呼び出されません)。私はまた、それと何か関係があった可能性のあるエラーを聞いてみましたが、そこには何もありませんでした(OnErrorは決して呼び出されません)。ログには、この問題に関連している可能性のある情報は含まれていませんでした。

VideoViewはアクティビティ、フラグメントなどでうまく動作するので、奇妙な問題ですが、(WindowManagerを使用して)グローバル(システム全体)レイアウトに追加すると、本当に変わってしまいます。

VideoViewでグローバル(システム全体)レイアウト内でビデオを再生することは可能ですか?

助けていただけたら幸いです!前もって感謝します!

コードスニペット:

CustomRelativeLayout

public class CustomRelativeLayout extends RelativeLayout { 


public static final String TAG = "Some Tag"; 


public CustomRelativeLayout(Context context) { 
    super(context); 
    init(); 
} 


//The rest of the constructors 
//go here... 


private void init() { 
    WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); 
    LayoutInflater inflater = LayoutInflater.from(getContext()); 

    View inflatedView = inflater.inflate(R.layout.my_layout, this, false); 

    VideoView videoView = (VideoView) inflatedView.findViewById(R.id.videoView); 
    videoView.setVideoURI(Uri.parse("http://www.html5videoplayer.net/videos/toystory.mp4")); 
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
     @Override 
     public void onPrepared(MediaPlayer mediaPlayer) { 
      Log.e(TAG, "The Video is ready to be played!"); 
      mediaPlayer.start(); 
     } 
    }); 

    //adding the inflated view 
    addView(inflatedView); 

    //adding to the windowManager 
    Point size = new Point(); 
    mWindowManager.getDefaultDisplay().getSize(size); 

    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
     size.x, 
     size.y 
    ); 
    layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL; 
    layoutParams.flags = (WindowManager.LayoutParams.FLAG_DIM_BEHIND | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); 
    layoutParams.dimAmount = 0f; 
    layoutParams.format = PixelFormat.RGBA_8888; 

    mWindowManager.addView(this, layoutParams); 
} 

}

レイアウト

<?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"> 

     <VideoView 
      android:id="@+id/videoView" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/black"/> 


</RelativeLayout> 

権限

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> 

答えて

0
View inflatedView = inflater.inflate(R.layout.my_layout, this, false); 
    //you should add view i think 
addView(inflatedView); 

VideoView videoView = (VideoView) inflatedView.findViewById(R.id.videoView); 
videoView.setVideoURI(Uri.parse("http://www.html5videoplayer.net/videos/toystory.mp4")); 
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { 
    @Override 
    public void onPrepared(MediaPlayer mediaPlayer) { 
     Log.e(TAG, "The Video is ready to be played!"); 
     mediaPlayer.start(); 
    } 
}); 
+0

しかし、膨張したビューが追加されました –

関連する問題