1

내 Windows-store 앱에서 노래를 재생하고 싶습니다. 문제는 다른 페이지로 이동할 때 사운드 재생이 멈추지 않아야하므로 페이지간에 MediaElement을 "공유"하고 싶습니다. 최신 Caliburn.Micro WinRT 포트를 사용하고 있습니다.페이지간에 미디어 요소 공유

이 문제에 대한 내 첫 번째 접근 방식은 DefaultViewMediaElement이 있고 여기에 2 행의 눈금이 있습니다. 두 번째 행에는 MediaElement (및 재생, 일시 정지 등을 처리하는 모든 컨트롤)이 들어 있으며 첫 번째 행에는 실제 콘텐츠를 삽입하려는 또 다른 frame이 있습니다.

작동하려면 해킹이 필요했습니다. 은 내가 CM과

public sealed partial class MainView 
{ 
    public MainView() 
    { 
     this.InitializeComponent(); 
     MainView.InitializeComponentStatic(this);  
    } 

    private static bool _isInitialized; 
    private static void InitializeComponentStatic(MainView mainView) 
    { 
     if (_isInitialized) return; 

     ((App)Application.Current).RegisterInstance(typeof(INavigationService2), 
      null, new NavigationService(mainView.ContentFrame)); 
     _isInitialized = true; 
    } 
} 

그때 내가 그 ContentFrame에 바인딩 내 StartViewModel을 시도하는 것이 등록, 지금
public class NavigationService : FrameAdapter, INavigationService2 
{ 
    public NavigationService(Frame frame, bool treatViewAsLoaded = false) 
     : base(frame, treatViewAsLoaded) { }   
} 

으로 새로운 인터페이스

public interface INavigationService2 : INavigationService { } 

내 자신의 NavigationService를 생성 하고있는 것

public class MainViewModel : Screen 
{ 
    public MainViewModel() 
    { 
     this.ContentFrame = new StartViewModel(((App) Application.Current).GetDefaultInstance<INavigationService2>()); 
    } 

    public DefaultViewModel ContentFrame { get; set; } 
} 

MainView 격자 안에 표시되지만 탐색은 더 이상 올바른보기 /보기 모델 (실제로는 MainViewModel을 다시로드합니다.)로 이동하지 않습니다.

정말 좋고 솔직하지 않기 때문에 원본 문제를 달성하는 방법에 대한 아이디어가 필요했습니다. 페이지/뷰간에 미디어 요소를 공유하는 것입니다.

+0

당신이 BackgroundAudio을 사용하지 않는 이유 솔루션입니다 : 여기 수행하는 방법에의 연습은? –

+0

대답은 이미 stackoverflow에 있었다 : http://stackoverflow.com/questions/10935107/global-mediaelement-that-continues-playing-after-navigating-to-other-page – esskar

답변

관련 문제