> ## 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.

# XAppCaptureStartUserRecord

> XAppCaptureStartUserRecord

# XAppCaptureStartUserRecord

以如同使用者觸發的方式進行錄製。如果玩家在錄製進行中暫停/限制其遊戲，錄製將會停止。錄製內容會儲存在使用者磁碟分割中。擷取設定以 GameDVR 設定為依據。一旦達到同時錄製上限，就必須呼叫 [XAppCaptureStopUserRecord](/zh-TW/reference/system/xappcapture/functions/xappcapturestopuserrecord) 或 [XAppCaptureCancelUserRecord](/zh-TW/reference/system/xappcapture/functions/xappcapturecanceluserrecord)，才能開始另一個錄製。此 API 的 Windows 支援將在未來版本中新增。

## 語法

```cpp theme={null}
HRESULT XAppCaptureStartUserRecord(
    XUserHandle requestingUser,
    uint32_t localIdBufferLength,
    char* localIdBuffer
)
```

### 參數

*requestingUser* \_In\_\
類型：XUserHandle

代表要求錄製之使用者的控制代碼。

*localIdBufferLength* \_In\_\
類型：uint32\_t

接收本機錄製識別碼之緩衝區的長度。

*localIdBuffer* \_Out\_\
類型：char\*

包含指定進行中錄製作業之本機識別碼的緩衝區。

### 傳回值

類型：HRESULT

函式結果。如需非 `S_OK` 的傳回值，請參閱 [XAppCapture 錯誤碼](/zh-TW/reference/system/xappcapture/xappcapture_errors)。

## 備註

函式成功完成時，localIdOfUserRecording 會包含錄製的本機識別碼，且必須儲存此識別碼，才能使用 [XAppCaptureStopUserRecord](/zh-TW/reference/system/xappcapture/functions/xappcapturestopuserrecord) 或 [XAppCaptureCancelUserRecord](/zh-TW/reference/system/xappcapture/functions/xappcapturecanceluserrecord) 停止特定錄製。

<Note>當配置的空間填滿時，將刪除較舊的剪輯，為新剪輯騰出空間。請使用 [PLS](/zh-TW/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members) (Persistent Local Storage)、connected storage (例如 [XGameSave](/zh-TW/reference/system/xgamesave/xgamesave_members) 或 [XGameSaveFiles](/zh-TW/reference/system/xgamesavefiles/xgamesavefiles_members)) 或類似的儲存系統，以在設定的期間內保留剪輯。</Note>

```cpp theme={null}
char localIdOfUserRecording[APPCAPTURE_MAX_LOCALID_LENGTH] = { '\0' };

XAppCaptureVideoCaptureSettings captureSettings = { 0 };
if (FAILED_LOG(XAppCaptureGetVideoCaptureSettings(&captureSettings)))
{
    return;
}

if (captureSettings.isCaptureByGamesAllowed)
{
    auto asyncBlock = std::make_unique<XAsyncBlock>();
    ZeroMemory(asyncBlock.get(), sizeof(*asyncBlock));
    asyncBlock->queue = g_taskQueue;
    asyncBlock->callback = [](XAsyncBlock* ab)
    {
        auto asyncBlock = std::unique_ptr<XAsyncBlock>(ab);

        XUserHandle user = nullptr;
        auto scopeExit = wil::scope_exit([&]()
        {
            if (user != nullptr)
            {
                XUserCloseHandle(user);
            }
        });

        if (FAILED_LOG(XUserAddResult(asyncBlock.get(), &user)))
        {
            return;
        }

        if (FAILED_LOG(XAppCaptureStartUserRecord(user, ARRAYSIZE(localIdOfUserRecording), localIdOfUserRecording)))
        {
            return;
        }
        appLog.AddLog("Recording started: localId = %s\n", localIdOfUserRecording);
    };

    if (SUCCEEDED_LOG(XUserAddAsync(
        XUserAddOptions::AddDefaultUserAllowingUI,
        asyncBlock.get())))
    {
        // Once started, release the pointer
        asyncBlock.release();
    }
}
```

## 需求

**標頭：** XAppCapture.h

**程式庫：** xgameruntime.lib

**支援的平台：** XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XAppCapture 成員](/zh-TW/reference/system/xappcapture/xappcapture_members)


## Related topics

- [XAppCaptureStartUserRecord](/reference/system/xappcapture/functions/xappcapturestartuserrecord.md)
- [XAppCaptureCancelUserRecord](/reference/system/xappcapture/functions/xappcapturecanceluserrecord.md)
- [XAppCaptureStopUserRecord](/reference/system/xappcapture/functions/xappcapturestopuserrecord.md)
- [XAppCaptureUserRecordingResult](/reference/system/xappcapture/structs/xappcaptureuserrecordingresult.md)
- [XAppCapture](/reference/system/xappcapture/xappcapture_members.md)
