|
3 | 3 | import android.os.Bundle; |
4 | 4 | import android.support.annotation.Nullable; |
5 | 5 | import android.support.v7.app.AppCompatActivity; |
| 6 | +import android.view.Menu; |
| 7 | +import android.view.MenuItem; |
6 | 8 | import android.widget.FrameLayout; |
| 9 | +import android.widget.LinearLayout; |
7 | 10 |
|
| 11 | +import tv.danmaku.ijk.media.example.fragments.SettingsFragment; |
8 | 12 | import tv.danmaku.ijk.media.example.widget.media.IjkVideoView; |
9 | 13 |
|
10 | 14 | public class MainActivity extends AppCompatActivity { |
| 15 | + |
11 | 16 | @Override |
12 | 17 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
13 | 18 | super.onCreate(savedInstanceState); |
| 19 | + LinearLayout rootLayout = new LinearLayout(this); |
| 20 | + rootLayout.setOrientation(LinearLayout.VERTICAL); |
14 | 21 | FrameLayout layout = new FrameLayout(this); |
15 | 22 | IjkVideoView videoView = new IjkVideoView(this); |
16 | | - layout.addView(videoView); |
17 | | - setContentView(layout); |
| 23 | + layout.setId(R.id.fragmentContainer); |
| 24 | + rootLayout.addView(videoView); |
| 25 | + rootLayout.addView(layout); |
| 26 | + setContentView(rootLayout); |
| 27 | + |
| 28 | + if (savedInstanceState == null) { |
| 29 | + getSupportFragmentManager().beginTransaction() |
| 30 | + .add(R.id.fragmentContainer, SettingsFragment.newInstance(), "tag") |
| 31 | + .commit(); |
| 32 | + } |
| 33 | + |
18 | 34 | videoView.setVideoPath("rtmp://118.89.52.73:1935/live/3601_2"); |
19 | 35 | videoView.start(); |
20 | 36 | } |
| 37 | + |
| 38 | + @Override |
| 39 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 40 | + menu.add("recreate").setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); |
| 41 | + return super.onCreateOptionsMenu(menu); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 46 | + if ("recreate".equals(item.getTitle())) { |
| 47 | + recreate(); |
| 48 | + return true; |
| 49 | + } |
| 50 | + return super.onOptionsItemSelected(item); |
| 51 | + } |
21 | 52 | } |
0 commit comments