|
| 1 | +package com.demo.widget.meis; |
| 2 | + |
| 3 | +import android.net.Uri; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.annotation.Nullable; |
| 6 | +import android.support.v7.app.AppCompatActivity; |
| 7 | +import android.view.View; |
| 8 | +import android.widget.ImageView; |
| 9 | +import android.widget.TextView; |
| 10 | + |
| 11 | +import com.demo.widget.R; |
| 12 | +import com.demo.widget.utils.Eyes; |
| 13 | +import com.google.android.exoplayer2.ExoPlayerFactory; |
| 14 | +import com.google.android.exoplayer2.SimpleExoPlayer; |
| 15 | +import com.google.android.exoplayer2.extractor.DefaultExtractorsFactory; |
| 16 | +import com.google.android.exoplayer2.extractor.ExtractorsFactory; |
| 17 | +import com.google.android.exoplayer2.source.ExtractorMediaSource; |
| 18 | +import com.google.android.exoplayer2.source.MediaSource; |
| 19 | +import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; |
| 20 | +import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; |
| 21 | +import com.google.android.exoplayer2.trackselection.TrackSelection; |
| 22 | +import com.google.android.exoplayer2.trackselection.TrackSelector; |
| 23 | +import com.google.android.exoplayer2.ui.SimpleExoPlayerView; |
| 24 | +import com.google.android.exoplayer2.upstream.BandwidthMeter; |
| 25 | +import com.google.android.exoplayer2.upstream.DataSource; |
| 26 | +import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; |
| 27 | +import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; |
| 28 | +import com.google.android.exoplayer2.util.Util; |
| 29 | +import com.meis.widget.photodrag.VideoDragRelativeLayout; |
| 30 | +import com.meis.widget.radius.RadiusTextView; |
| 31 | + |
| 32 | +/** |
| 33 | + * Created by wenshi on 2018/5/23. |
| 34 | + * Description |
| 35 | + */ |
| 36 | +public class MeiVideoDragActivity extends AppCompatActivity { |
| 37 | + |
| 38 | + TextView mTvComment; |
| 39 | + TextView mTvAttention; |
| 40 | + RadiusTextView mTvName; |
| 41 | + ImageView mIvClose; |
| 42 | + SimpleExoPlayerView mPlayerView; |
| 43 | + |
| 44 | + VideoDragRelativeLayout mDragLayout; |
| 45 | + |
| 46 | + @Override |
| 47 | + protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 48 | + super.onCreate(savedInstanceState); |
| 49 | + setContentView(R.layout.mei_video_drag_activity); |
| 50 | + Eyes.translucentStatusBar(this, true); |
| 51 | + |
| 52 | + mTvComment = findViewById(R.id.tv_comment); |
| 53 | + mTvAttention = findViewById(R.id.tv_attention); |
| 54 | + mTvName = findViewById(R.id.tv_name); |
| 55 | + mIvClose = findViewById(R.id.iv_close); |
| 56 | + mDragLayout = findViewById(R.id.rl_drag); |
| 57 | + mPlayerView = findViewById(R.id.play_view); |
| 58 | + |
| 59 | + //视频源 |
| 60 | + BandwidthMeter bandwidthMeter = new DefaultBandwidthMeter(); |
| 61 | + TrackSelection.Factory trackFactory = new AdaptiveTrackSelection.Factory(bandwidthMeter); |
| 62 | + TrackSelector trackSelector = new DefaultTrackSelector(trackFactory); |
| 63 | + SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); |
| 64 | + mPlayerView.setPlayer(player); |
| 65 | + |
| 66 | + DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter(); |
| 67 | + DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this |
| 68 | + , Util.getUserAgent(this, "MyApplication") |
| 69 | + , defaultBandwidthMeter); |
| 70 | + ExtractorsFactory extractorsFactory = new DefaultExtractorsFactory(); |
| 71 | + Uri uri = Uri.parse("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4"); |
| 72 | + MediaSource mediaSource = new ExtractorMediaSource(uri |
| 73 | + , dataSourceFactory, extractorsFactory, null, null); |
| 74 | + player.prepare(mediaSource); |
| 75 | + |
| 76 | + mDragLayout.setOnVideoDragListener(new VideoDragRelativeLayout.OnVideoDragListener() { |
| 77 | + @Override |
| 78 | + public void onStartDrag() { |
| 79 | + mTvComment.setVisibility(View.GONE); |
| 80 | + mTvAttention.setVisibility(View.GONE); |
| 81 | + mTvName.setVisibility(View.GONE); |
| 82 | + mIvClose.setVisibility(View.GONE); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public void onRelease(boolean dismiss) { |
| 87 | + if (!dismiss) { |
| 88 | + mTvComment.setVisibility(View.VISIBLE); |
| 89 | + mTvAttention.setVisibility(View.VISIBLE); |
| 90 | + mTvName.setVisibility(View.VISIBLE); |
| 91 | + mIvClose.setVisibility(View.VISIBLE); |
| 92 | + } else { |
| 93 | + //根据转场来执行相应的动画 |
| 94 | + finish(); |
| 95 | + } |
| 96 | + } |
| 97 | + }); |
| 98 | + |
| 99 | + mIvClose.setOnClickListener(new View.OnClickListener() { |
| 100 | + @Override |
| 101 | + public void onClick(View v) { |
| 102 | + finish(); |
| 103 | + } |
| 104 | + }); |
| 105 | + |
| 106 | + } |
| 107 | +} |
0 commit comments