【问题标题】:Get current playback time of background audio after navigating away and back to the page - UWP导航离开并返回页面后获取背景音频的当前播放时间 - UWP
【发布时间】:2017-07-22 11:36:03
【问题描述】:

我正在使用 MediaPlayer 类播放音频,并在清单中启用了背景音频功能。我正在使用自己的播放/暂停按钮来控制播放。

一切正常,除了当我离开页面并返回时,我丢失了正在播放的背景音频的当前播放进度,该音频正在显示在 TextBlock 上。

如何连接回该背景音频?我似乎找不到解决方案。

谢谢

【问题讨论】:

  • 只需保留对在某处播放音乐的 MediaPlayer 的引用(可能是静态变量?),然后像第一次一样将其连接起来。

标签: c# uwp


【解决方案1】:

感谢 Johnny 和 Vimal 的正确指点。我正在使用下面的类,它总是返回一个实例......它有效!

public class PlaybackService
{
    private static PlaybackService instance;

    public static PlaybackService Instance
    {
        get
        {
            if (instance == null)
                instance = new PlaybackService();

            return instance;
        }
    }

    public MediaPlayer Player { get; private set; }

    public PlaybackService()
    {
        // Create the player instance
        Player = new MediaPlayer();

    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-20
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多