Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>VideoPlayerActivity extends Activity { /** Called when the activity is first created. */ MediaPlayer mp; File mPath; String datavideo = "/sdcard/musicfiles.mp4"; String datamusic = "/sdcard/musicfileone.mp3"; String urlString = "http://192.168.1.92/Stream/song.mp3"; String urlVodeo = "http://192.168.1.92/Stream/Wildlife.mp4"; Button btnVideo, btnAudio, btnViewVideo; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); btnVideo = (Button) findViewById(R.id.btnStoreVideo); btnAudio = (Button) findViewById(R.id.btnstoreAudio); btnViewVideo = (Button) findViewById(R.id.btnViewVideo); btnVideo.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { // TODO Auto-generated method stub try { setDataSourc(datavideo); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnAudio.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub try { setDataSource(datamusic); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnViewVideo.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(VideoPlayerActivity.this, PlayingVideo.class); startActivity(intent); } }); } private void setDataSource(String path) throws IOException { // HttpClient client = new DefaultHttpClient(); // HttpPost post = new HttpPost(urlString); // HttpResponse response = client.execute(post); // HttpEntity cn = response.getEntity(); URL url = new URL(urlString); URLConnection cn = url.openConnection(); cn.connect(); InputStream stream = cn.getInputStream();// getContent(); if (stream == null) { throw new RuntimeException("stream is null"); } mPath = new File(datamusic); mPath.createNewFile(); FileOutputStream out = new FileOutputStream(mPath); byte buf[] = new byte[128]; do { int numRead = stream.read(buf); if (numRead &lt;= 0) { break; } out.write(buf, 0, numRead); } while (true); mp = new MediaPlayer(); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mp.setDataSource(path); mp.prepare(); mp.start(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } try { stream.close(); } catch (Exception ex) { String sDummy = ex.toString(); System.out.println("hello dummy" + sDummy); } } private void setDataSourc(String path) throws IOException { // HttpClient client = new DefaultHttpClient(); // HttpPost post = new HttpPost(urlString); // HttpResponse response = client.execute(post); // HttpEntity cn = response.getEntity(); URL url = new URL(urlVodeo); URLConnection cn = url.openConnection(); cn.connect(); InputStream stream = cn.getInputStream();// getContent(); if (stream == null) { throw new RuntimeException("stream is null"); } mPath = new File(datavideo); mPath.createNewFile(); FileOutputStream out = new FileOutputStream(mPath); byte buf[] = new byte[128]; do { int numRead = stream.read(buf); if (numRead &lt;= 0) { break; } out.write(buf, 0, numRead); } while (true); // mp = new MediaPlayer(); // mp.setAudioStreamType(AudioManager.STREAM_MUSIC); try { // mp.setDataSource(path); // mp.prepare(); // mp.start(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } try { stream.close(); } catch (Exception ex) { String sDummy = ex.toString(); System.out.println("hello dummy" + sDummy); } } } </code></pre> <p>I had used the above code in my application to solve the problem,may this help you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload