Last active
March 21, 2017 03:02
-
-
Save Evin1-/1455d910f073c5fbd491c1a728cc8ba6 to your computer and use it in GitHub Desktop.
Minimal MediaPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_margin="16dp" | |
android:orientation="vertical" | |
tools:context="com.example.myapplication.MainActivity"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Hello World!" /> | |
<SurfaceView | |
android:id="@+id/a_main_surface" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.INTERNET" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
private static final String VIDEO_URL = "http://techslides.com/demos/sample-videos/small.mp4"; | |
private SurfaceView surfaceView; | |
private SurfaceHolder surfaceHolder; | |
private MediaPlayer mediaPlayer; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
surfaceView = (SurfaceView) findViewById(R.id.a_main_surface); | |
surfaceHolder = surfaceView.getHolder(); | |
surfaceHolder.addCallback(new SurfaceHolder.Callback() { | |
@Override | |
public void surfaceCreated(SurfaceHolder surfaceHolder) { | |
mediaPlayer = MediaPlayer.create(MainActivity.this, Uri.parse(VIDEO_URL)); | |
mediaPlayer.setDisplay(surfaceHolder); | |
mediaPlayer.start(); | |
} | |
@Override | |
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) { | |
} | |
@Override | |
public void surfaceDestroyed(SurfaceHolder surfaceHolder) { | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment