> ## 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](/reference/system/xappcapture/functions/xappcapturestopuserrecord) 或 [XAppCaptureCancelUserRecord](/reference/system/xappcapture/functions/xappcapturecanceluserrecord) 后才能开始另一个录制。此 API 的 Windows 支持将在将来的版本中添加。

## Syntax

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

### Parameters

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

表示请求录制的用户的句柄。

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

接收本地录制 ID 的缓冲区长度。

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

包含指定正在进行的录制操作的本地 ID 的缓冲区。

### Return value

类型：HRESULT

函数结果。有关非 `S_OK` 返回值，请参阅 [XAppCapture 错误代码](/reference/system/xappcapture/xappcapture_errors)。

## Remarks

在函数成功完成后，localIdOfUserRecording 包含录制的本地 ID，必须将其存储起来，以便使用 [XAppCaptureStopUserRecord](/reference/system/xappcapture/functions/xappcapturestopuserrecord) 或 [XAppCaptureCancelUserRecord](/reference/system/xappcapture/functions/xappcapturecanceluserrecord) 停止特定录制。

<Note>当分配的空间被填满时，较旧的剪辑将被删除以为新剪辑腾出空间。请使用 [PLS](/reference/system/xpersistentlocalstorage/xpersistentlocalstorage_members)（持久本地存储）、已连接存储（例如 [XGameSave](/reference/system/xgamesave/xgamesave_members) 或 [XGameSaveFiles](/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();
    }
}
```

## Requirements

**头文件：** XAppCapture.h

**库：** xgameruntime.lib

**受支持的平台：** XBOX One 系列主机和 XBOX Series 主机

## See also

[XAppCapture members](/reference/system/xappcapture/xappcapture_members)


## Related topics

- [XAppCaptureCancelUserRecord](/zh-CN/reference/system/xappcapture/functions/xappcapturecanceluserrecord.md)
- [XAppCaptureUserRecordingResult](/zh-CN/reference/system/xappcapture/structs/xappcaptureuserrecordingresult.md)
- [XAppCaptureStopUserRecord](/zh-CN/reference/system/xappcapture/functions/xappcapturestopuserrecord.md)
- [XAppCapture](/zh-CN/reference/system/xappcapture/xappcapture_members.md)
- [XAppCaptureRecordTimespan](/zh-CN/reference/system/xappcapture/functions/xappcapturerecordtimespan.md)
