0

我的媒體錄像機正在錄製視頻後錄製視頻,我正在預覽我的視頻(很好)。 現在已將此視頻上傳到本地http服務器。 並最終從服務器獲取此視頻播放,但它顯示無法播放視頻。從服務器下載後無法播放視頻

任何建議,其中實際的錯誤是... thanx的幫助。

  1. MediaRecorder

    this.mediaRecorder = new MediaRecorder(); 
    this.mediaRecorder.setCamera(this.camera); 
    camera.unlock(); 
    this.mediaRecorder.setCamera(camera); 
    this.mediaRecorder.setOrientationHint(90); 
    this.mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT); 
    this.mediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT); 
    CamcorderProfile camcorderProfile_HQ = CamcorderProfile.get(CamcorderProfile.QUALITY_480P); 
    this.mediaRecorder.setProfile(camcorderProfile_HQ); 
    this.mediaRecorder.setOutputFile(this.initFile().getAbsolutePath()); 
    this.mediaRecorder.setMaxDuration(60000); // Set max duration 60 sec. 
    this.mediaRecorder.setMaxFileSize(5000000); 
    
    
    this.mediaRecorder.setPreviewDisplay(this.cameraPreview.getHolder().getSurface()); 
    
    
        try { 
        this.mediaRecorder.prepare(); 
        // start the actual recording 
        // throws IllegalStateException if not prepared 
        this.mediaRecorder.start(); 
        Toast.makeText(this, R.string.recording, Toast.LENGTH_SHORT).show(); 
        // enable the stop button by indicating that we are recording 
        this.toggleButtons(true); 
    } catch (Exception e) { 
        Log.wtf(TAG, "Failed to prepare MediaRecorder", e); 
        Toast.makeText(this, R.string.cannot_record, Toast.LENGTH_SHORT).show(); 
        this.releaseMediaRecorder(); 
    } 
    
  2. 視頻視圖

    Uri uri = Uri.parse("/data/data/com.example.mediarecorder/files/"+ messageList.get(position)); //do not add any extension 
    
          video.setVideoURI(uri); 
          video.requestFocus(); 
          setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 
          video.setKeepScreenOn(true); 
          System.out.println(uri + " "+ uri.getEncodedAuthority()+ " "+ uri.decode(data_type) + " "+ uri.getUserInfo() + " "+ uri.describeContents()); 
          video.start(); 
    

回答

4

無法從內部存儲通過videoview播放視頻,因爲文件沒有世界可讀權限。您必須使用surfaceView和媒體播放器類創建自定義視頻播放器。然後,你必須創建你需要發揮並傳遞到mediaPlayer.setDataSource()文件的文件描述符:

FileInputStream inputStream = new FileInputStream(videoPath); 
//assume videoPath = getFilesDir().getAbsolutePath()) + File.separator + "Video.mp4" 
mp.setDataSource(inputStream.getFD()); 
     mp.prepareAsync(); 
     try { 
      mp.setOnPreparedListener(new OnPreparedListener() { 

       @Override 
       public void onPrepared(MediaPlayer mplayer) { 
        if (mp != null) { 
         mp.start(); 
        } 
       } 
      }); 
+0

其實我忘了提,我上傳視頻到http服務器(filezila)和我後我正在解析uri。 它是在如Nexus 5更高版本設備的但不是在其他設備,諸如karbon和星系標籤運行。 @Sunny –