Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Android
  4. Android How to play media files(.mp4) from assets folder

Android How to play media files(.mp4) from assets folder

Scheduled Pinned Locked Moved Android
javaandroidcomdebugginghelp
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    josephdalebert
    wrote on last edited by
    #1

    I have a problem with my code wherein i cant trace the problem on the second try where the player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); cannot determine the AssetFileDescriptor on the 1st try catch statement.. it says that the local variable is not initialized.. but if i initialized it to null.. the app will unfortunately closed.. package com.thesis.americansignlanguage; import java.io.IOException; import android.app.Activity; import android.content.res.AssetFileDescriptor; import android.media.MediaPlayer; import android.os.Bundle; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.widget.TextView; import android.widget.VideoView; public class Videocompareclass extends Activity { String get; VideoView gesture; int charIndex; char[] getArray; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.gesturecompare); SurfaceView videoView = (SurfaceView)findViewById(R.id.sf_view); SurfaceHolder holder = videoView.getHolder(); Bundle gotWord = getIntent().getExtras(); get = gotWord.getString("key"); TextView Word = (TextView)findViewById(R.id.textView1); Word.setText(get); AssetFileDescriptor afd; try { afd = getAssets().openFd("hello.mp4"); } catch(IOException e1) { e1.printStackTrace(); } MediaPlayer player = new MediaPlayer(); if(player.isPlaying()) { player.reset(); } player.setDisplay(holder); try { player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); player.prepare(); } catch(IllegalArgumentException e) { e.printStackTrace(); } catch(IllegalStateException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } player.start(); } }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups