Search in sources :

Example 6 with VideoView

use of android.widget.VideoView in project AndroidSDK-RecipeBook by gabu.

the class Recipe086 method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        // 正しい結果が得られなかった場合の処理
        return;
    }
    if (requestCode == REQUEST_CODE_1) {
        // このbitmapが撮影した画像データです。
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        ImageView imageView = (ImageView) findViewById(R.id.image);
        imageView.setImageBitmap(bitmap);
    } else if (requestCode == REQUEST_CODE_2) {
        // dataがnullなので、以下のように取得しないで
        // Uri uri = data.getData();
        // インテントにセットしたUri mPictureUriを使う
        // エラーが発生していなければ、
        // このmPictureUriに撮影した写真データのUriが入っている。
        ImageView imageView = (ImageView) findViewById(R.id.image);
        imageView.setImageURI(mPictureUri);
    } else if (requestCode == REQUEST_CODE_3) {
        // 撮影された動画のUriを取得
        Uri uri = data.getData();
        // VideoViewを取得
        VideoView v = (VideoView) findViewById(R.id.VideoView01);
        // VideoViewにはUriがセットできます。
        v.setVideoURI(uri);
        // 再生します。
        v.start();
    } else if (requestCode == REQUEST_CODE_4) {
        // 録音された音声のUriを取得
        Uri uri = data.getData();
        // メディアプレーヤーで再生する例
        MediaPlayer mp = new MediaPlayer();
        try {
            // Uriをセット
            mp.setDataSource(getApplicationContext(), uri);
            // 準備
            mp.prepare();
            // 再生!
            mp.start();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else if (requestCode == REQUEST_CODE_5) {
        String resultStr = "";
        // 認識結果のリストを取得
        // 似ている言葉など、複数の結果がある場合もある。
        List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        for (String result : results) {
            resultStr += (result + "\n");
        }
        TextView textView = (TextView) findViewById(R.id.text);
        textView.setText(resultStr);
    }
}
Also used : Bitmap(android.graphics.Bitmap) VideoView(android.widget.VideoView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) IOException(java.io.IOException) Uri(android.net.Uri) MediaPlayer(android.media.MediaPlayer)

Example 7 with VideoView

use of android.widget.VideoView in project android_frameworks_base by DirtyUnicorns.

the class VideoViewCaptureActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mVideoView = new VideoView(this);
    mVideoView.setOnPreparedListener(mp -> {
        mp.setLooping(true);
        mVideoWidth = mp.getVideoWidth();
        mVideoHeight = mp.getVideoHeight();
        mVideoView.start();
    });
    Uri uri = Uri.parse("android.resource://com.android.test.hwui/" + R.raw.colorgrid_video);
    mVideoView.setVideoURI(uri);
    Button button = new Button(this);
    button.setText("Copy bitmap to /sdcard/surfaceview.png");
    button.setOnClickListener((View v) -> {
        final Bitmap b = Bitmap.createBitmap(mVideoWidth, mVideoHeight, Bitmap.Config.ARGB_8888);
        PixelCopy.request(mVideoView, b, (int result) -> {
            if (result != PixelCopy.SUCCESS) {
                Toast.makeText(VideoViewCaptureActivity.this, "Failed to copy", Toast.LENGTH_SHORT).show();
                return;
            }
            try {
                try (FileOutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory() + "/surfaceview.png")) {
                    b.compress(Bitmap.CompressFormat.PNG, 100, out);
                }
            } catch (Exception e) {
            // Ignore
            }
        }, mVideoView.getHandler());
    });
    FrameLayout content = new FrameLayout(this);
    LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(button, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layout.addView(mVideoView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
    content.addView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
    setContentView(content);
}
Also used : Bitmap(android.graphics.Bitmap) Button(android.widget.Button) VideoView(android.widget.VideoView) FileOutputStream(java.io.FileOutputStream) FrameLayout(android.widget.FrameLayout) Uri(android.net.Uri) View(android.view.View) VideoView(android.widget.VideoView) LinearLayout(android.widget.LinearLayout)

Example 8 with VideoView

use of android.widget.VideoView in project DanmakuFlameMaster by Bilibili.

the class MainActivity method findViews.

private void findViews() {
    mMediaController = findViewById(R.id.media_controller);
    mBtnRotate = (Button) findViewById(R.id.rotate);
    mBtnHideDanmaku = (Button) findViewById(R.id.btn_hide);
    mBtnShowDanmaku = (Button) findViewById(R.id.btn_show);
    mBtnPauseDanmaku = (Button) findViewById(R.id.btn_pause);
    mBtnResumeDanmaku = (Button) findViewById(R.id.btn_resume);
    mBtnSendDanmaku = (Button) findViewById(R.id.btn_send);
    mBtnSendDanmakuTextAndImage = (Button) findViewById(R.id.btn_send_image_text);
    mBtnSendDanmakus = (Button) findViewById(R.id.btn_send_danmakus);
    mBtnRotate.setOnClickListener(this);
    mBtnHideDanmaku.setOnClickListener(this);
    mMediaController.setOnClickListener(this);
    mBtnShowDanmaku.setOnClickListener(this);
    mBtnPauseDanmaku.setOnClickListener(this);
    mBtnResumeDanmaku.setOnClickListener(this);
    mBtnSendDanmaku.setOnClickListener(this);
    mBtnSendDanmakuTextAndImage.setOnClickListener(this);
    mBtnSendDanmakus.setOnClickListener(this);
    // VideoView
    VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
    // DanmakuView
    // 设置最大显示行数
    HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
    // 滚动弹幕最大显示5行
    maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5);
    // 设置是否禁止重叠
    HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
    overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
    overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);
    mDanmakuView = (IDanmakuView) findViewById(R.id.sv_danmaku);
    mContext = DanmakuContext.create();
    mContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3).setDuplicateMergingEnabled(false).setScrollSpeedFactor(1.2f).setScaleTextSize(1.2f).setCacheStuffer(new SpannedCacheStuffer(), // 图文混排使用SpannedCacheStuffer
    mCacheStufferAdapter).setMaximumLines(maxLinesPair).preventOverlapping(overlappingEnablePair);
    if (mDanmakuView != null) {
        mParser = createParser(this.getResources().openRawResource(R.raw.comments));
        mDanmakuView.setCallback(new master.flame.danmaku.controller.DrawHandler.Callback() {

            @Override
            public void updateTimer(DanmakuTimer timer) {
            }

            @Override
            public void drawingFinished() {
            }

            @Override
            public void danmakuShown(BaseDanmaku danmaku) {
            //                    Log.d("DFM", "danmakuShown(): text=" + danmaku.text);
            }

            @Override
            public void prepared() {
                mDanmakuView.start();
            }
        });
        mDanmakuView.setOnDanmakuClickListener(new IDanmakuView.OnDanmakuClickListener() {

            @Override
            public boolean onDanmakuClick(IDanmakus danmakus) {
                Log.d("DFM", "onDanmakuClick: danmakus size:" + danmakus.size());
                BaseDanmaku latest = danmakus.last();
                if (null != latest) {
                    Log.d("DFM", "onDanmakuClick: text of latest danmaku:" + latest.text);
                    return true;
                }
                return false;
            }

            @Override
            public boolean onViewClick(IDanmakuView view) {
                mMediaController.setVisibility(View.VISIBLE);
                return false;
            }
        });
        mDanmakuView.prepare(mParser, mContext);
        mDanmakuView.showFPS(true);
        mDanmakuView.enableDanmakuDrawingCache(true);
    }
    if (mVideoView != null) {
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });
        mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/1.flv");
    }
}
Also used : IDanmakuView(master.flame.danmaku.controller.IDanmakuView) HashMap(java.util.HashMap) VideoView(android.widget.VideoView) BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) SpannedCacheStuffer(master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus) MediaPlayer(android.media.MediaPlayer)

Example 9 with VideoView

use of android.widget.VideoView in project Small by wequick.

the class VideoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    VideoView videoView = (VideoView) findViewById(R.id.video_view);
    final String uri = "android.resource://" + getPackageName() + "/" + R.raw.fix_429;
    videoView.setVideoURI(Uri.parse(uri));
    // Loop
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.setLooping(true);
        }
    });
    // Play
    videoView.start();
}
Also used : VideoView(android.widget.VideoView) MediaPlayer(android.media.MediaPlayer)

Example 10 with VideoView

use of android.widget.VideoView in project Tapad by berict.

the class TutorialHelper method playMotionAnimation.

void playMotionAnimation(int btnId, int phId, int motionId, Activity activity) {
    VideoView videoView;
    View placeholder;
    videoView = (VideoView) activity.findViewById(btnId);
    placeholder = (View) activity.findViewById(phId);
    animator(videoView, placeholder, motionId, activity);
    Log.i("MotionAnimation", "Animation played on " + activity.getResources().getResourceEntryName(phId));
}
Also used : VideoView(android.widget.VideoView) View(android.view.View) VideoView(android.widget.VideoView)

Aggregations

VideoView (android.widget.VideoView)21 View (android.view.View)13 MediaPlayer (android.media.MediaPlayer)10 Uri (android.net.Uri)8 Bitmap (android.graphics.Bitmap)7 FrameLayout (android.widget.FrameLayout)6 Button (android.widget.Button)5 LinearLayout (android.widget.LinearLayout)5 TextView (android.widget.TextView)4 FileOutputStream (java.io.FileOutputStream)4 ImageView (android.widget.ImageView)3 IOException (java.io.IOException)3 IDanmakuView (master.flame.danmaku.controller.IDanmakuView)3 DanmakuTimer (master.flame.danmaku.danmaku.model.DanmakuTimer)3 OnClickListener (android.view.View.OnClickListener)2 MediaController (android.widget.MediaController)2 HashMap (java.util.HashMap)2 BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)2 IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)2 LightningView (acr.browser.lightning.view.LightningView)1