> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XAppCaptureReadLocalStream

> XAppCaptureReadLocalStream

# XAppCaptureReadLocalStream

以前に [XAppCaptureRecordTimespan](/reference/system/xappcapture/functions/xappcapturerecordtimespan) の呼び出しで生成された .mp4 ファイルの内容を読み取ります。

## 構文

```cpp theme={null}
HRESULT XAppCaptureReadLocalStream(
  XAppCaptureLocalStreamHandle handle,
  size_t startPosition,
  uint32_t bytesToRead,
  uint8_t * buffer,
  uint32_t * bytesWritten
)
```

### パラメーター

*handle* \_In\_\
型: XAppCaptureLocalStreamHandle

以前に [XAppCaptureRecordTimespan](/reference/system/xappcapture/functions/xappcapturerecordtimespan) によって作成されたローカル録画ファイルへのハンドルです。

*startPosition* \_In\_\
型: size\_t

ストリーム内の開始位置です。

*bytesToRead* \_In\_\
型: uint32\_t

読み取るバイト数です。

*buffer* \_Out\_writes\_to\_(bytesToRead, \*bytesWritten)\
型: uint8\_t \*

ストリーム データを書き込むバッファーです。

*bytesWritten* \_Out\_\
型: uint32\_t \*

関数の完了時に、指定されたバッファーに書き込まれたバイト数が含まれます。

### 戻り値

型: HRESULT

関数の結果です。

## 解説

同時に存在できる録画は最大 2 つです。 ストリームを閉じるときに、ファイルは削除されます。 ゲームを終了すると、古いファイルを防ぐために録画は自動的に削除されます。

[XAppCaptureLocalResult](/reference/system/xappcapture/structs/xappcapturelocalresult) を取得する方法については、[XAppCaptureRecordTimespan](/reference/system/xappcapture/functions/xappcapturerecordtimespan) を参照してください。

```cpp theme={null}
const int MAX_DATA = 1024;

XAppCaptureLocalResult localResult = {0};
XAppCaptureLocalStreamHandle localHandle = nullptr;
HANDLE file = INVALID_HANDLE_VALUE;

uint8_t buffer[MAX_DATA];
/* 5 seconds, for example. You should call XAppCaptureGetVideoCaptureSettings() to ensure there's sufficient duration available */
uint64_t durationInMs = 5000;
size_t totalBytesRead = 0;
size_t fileSize = 0;

XAppCaptureRecordTimespan(nullptr, durationInMs, &localResult);

localHandle = localResult.clipHandle;
fileSize = localResult.fileSizeInBytes;

/* T:\ is one example of a writeable local directory. Be aware that the T:\ drive can be invalidated on suspend or resume, and as such it's better to use PLS */ 
file = CreateFileA("T:\\MyFile.mp4", GENERIC_READ | GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);

while (totalBytesRead < fileSize)
{
    uint32_t bytesRead = 0;
    uint32_t bytesWritten = 0;
    if (SUCCEEDED(XAppCaptureReadLocalStream(localHandle, totalBytesRead, sizeof(buffer), buffer, &bytesRead)))
    {
        WriteFile(file, buffer, bytesRead, &bytesWritten, NULL);

        totalBytesRead += bytesRead;
    }
    else
    {
        break;
    }
}

/* You must always close a local stream handle even if nothing was read in */
XAppCaptureCloseLocalStream(localHandle);

```

## 要件

**ヘッダー:** XAppCapture.h

**ライブラリ:** xgameruntime.lib

**サポートされているプラットフォーム:** Windows、XBOX One ファミリー本体、XBOX Series 本体

## 関連項目

[XAppCapture メンバー](/reference/system/xappcapture/xappcapture_members)


## Related topics

- [XAppCaptureLocalResult](/ja-jp/reference/system/xappcapture/structs/xappcapturelocalresult.md)
- [XAppCaptureRecordTimespan](/ja-jp/reference/system/xappcapture/functions/xappcapturerecordtimespan.md)
- [XAppCapture](/ja-jp/reference/system/xappcapture/xappcapture_members.md)
- [GDK 向け Unity C# API ラッパー](/ja-jp/build/gdk-and-engines/unity/unity-api-wrappers.md)
- [XAppCaptureReadScreenshotStream](/ja-jp/reference/system/xappcapture/functions/xappcapturereadscreenshotstream.md)
