想要在包中打包一个小视频进行部署

有没有办法以编程方式引用一个非常小的视频文件,并将其包含在teh包中 - 即我不想让它在SD卡上分开。我想把它放在'raw'包目录中。 例如。 MPEG4在'raw'中称为'video' 我试图弄清楚Uri.parse()的正确格式,但它击败了我。我认为它应该像R.raw(在为音频设置媒体播放器时使用myMediaPlayer = MediaPlayer.create(这,R.raw.audiocameralive1) - 但它似乎不是。 有什么建议 奥利弗     
已邀请:
我看到有很多观点,所以如果有人在寻找解决方案,这就是我最终做的 - 似乎工作正常。可能更干净的方式做同样的事情,但这个对我有意义...... 奥利弗
public class ShowVideoActivity extends Activity 
    implements SurfaceHolder.Callback, 
    OnErrorListener,
    OnPreparedListener,
    OnCompletionListener
{

/** Called when the activity is first created. */
private MediaPlayer myMediaPlayer;
boolean bolMediaPlayerIsReleased = false;

// The SurfaceHolder and SurfaceView are used to display the video
// By implementing the SurfaceHolder.Callback interface means that we have
// to implement surfaceChanged(), surfaceCreated() and surfaceDestroyed()
private SurfaceView videoSurface;
private SurfaceHolder videoHolder;

Display currentDisplay;

@Override
public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.showvideo);  // Inflate ShowVideo

    // Identify the Surface that will be used to hold the camera image
    videoSurface = (SurfaceView)findViewById(R.id.videosurface);
    // The SurfaceHolder 'monitors' activity on the Surface
    videoHolder = videoSurface.getHolder();
    videoHolder.setKeepScreenOn(true);

    // Data will be Pushed onto the buffers external to the surface
    videoHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    videoHolder.setKeepScreenOn(true);
    // Let the monitor know that 'this' activity is responsible for
    // all the callback functions.
    videoHolder.addCallback(this);
    // It is now up to the 'callbacks' to do any further processing

    myMediaPlayer = MediaPlayer.create(this,R.raw.filename);
    myMediaPlayer.setOnCompletionListener(this);
    myMediaPlayer.setOnErrorListener(this);
    myMediaPlayer.setOnPreparedListener(this);
    myMediaPlayer.setOnCompletionListener(this);
    currentDisplay = getWindowManager().getDefaultDisplay();
    }

// Set up a listener to wait for MediaPlayer End  (Is this PlaybackCompleted()?)
public void onCompletion(MediaPlayer mp)
    {
    Wrapup(mp);
    }

public void surfaceCreated(SurfaceHolder CreatedHolder) {
    // Surface created, now it is possible to set the preview
    myMediaPlayer.setDisplay(CreatedHolder);
    }

public void surfaceDestroyed(SurfaceHolder DestroyedHolder) 
    {
    if (myMediaPlayer != null)
        {
        if (myMediaPlayer.isPlaying() )
            myMediaPlayer.stop();
        myMediaPlayer.release();
        bolMediaPlayerIsReleased = true;
        }
    }

public void surfaceChanged(SurfaceHolder ChangedHolder, int intFormat, int intWidth, int intHeight) 
    {
    if (myMediaPlayer.isPlaying())
        return;
    else
        {
        setVideoSurfaceSize(myMediaPlayer);
        myMediaPlayer.start();
        }
}

public boolean onError(MediaPlayer mPlayer, int intError, int intExtra)
    {
    return false;
    }

public void onPrepared(MediaPlayer mPlayer)
    {
    setVideoSurfaceSize(mPlayer);
    mPlayer.start();
    // From the 'Started' mode, the player can either be 'Stopped', 'Paused' or PlaybackCompleted'
    }  // End onPrepared


public void Wrapup(MediaPlayer mp)
    {
    if (mp != null)
        {
        if (myMediaPlayer.isPlaying() )
            mp.stop();
        mp.release();
        bolMediaPlayerIsReleased = true;
        }

    // Now clean up before terminating.  This is ESSENTIAL
    // If cleanup is NOT done then the surfaceDestroyed will get called
    // and screw up everything
    // Firstly remove the callback
    videoHolder.removeCallback(this);  // Prevents callbacks when the surface is destroyed

    ShowVideoActivity.this.finish();                    
    }
}
    
使用
Activity.getAssets()
得到
AssetManager
。使用
open
加载文件。     

要回复问题请先登录注册